Jump to content
  • Advertisement
Sign in to follow this  

Getting lengh of vector with slope. Trigo problem

This topic is 4081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there! How are you? I have problem. I have object Tank and tank have Canon :) Canon can be with different slope: I added a picture to show what i mean Now i'll explain what i have and what i need to find. I have and object in my case tank and his axises. A point coordinates are x=0 y=0 I also know that alfa angle can be between 0<=a<=2Pi The red line is canon of the tank, Now i need to calculate B point coordinates according to the current angle. Lets say alfa = 90grad = PI/2rad => B coordinates are x=0 y=y1 If alfa = 180grad = PIrad => b x=-x1 y=0 I need system of equations for x and y separately that will dependance on alfa angle. I hope you got it and will be able to help me. Thanks!

Share this post

Link to post
Share on other sites
The sine function (which usually takes radians) will give you a value that is equal to if you had taken the length of the side opposite from the corner whose angle measurement you used, and divided it by the length of the hypotenuse, the side that is opposite from the 90° angle. Side-opposite over hypotenuse, in short. To get just the length of the opposite side, just multiply the result of the sine function by the hypotenuse length. That will cancel out the hypotenuse component from the sine function, leaving the side-opposite length. In your case, side-opposite corresponds to the y axis.

Similarly, cosine returns side-adjacent over hypotenuse. Cosine multiplied by hypotenuse will therefore give you the side-adjacent length, or x in this case.

---- |
Hypotenuse ---- |
---- | Opposite
---- | Side
---- \ <-- Angle __|
---- | | |
+------------------------------+ <-- Right Angle
Adjacent Side

So you'll need to know the length of your turret barrel. Given that (as barrel_length), and the angle in radians (as theta, the most common Greek letter for angles), x and y are therefore:

x = cos(theta) * barrel_length;
y = sin(theta) * barrel_length;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!