Jump to content
  • Advertisement
Sign in to follow this  
fboy

difference between two angles

This topic is 3718 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

I'm having some trouble trying to figure out how to find the distance between two angles from each other that range between -pi and pi. (ie, if one angle is -3.1 and the other +3.1, the distance should be ~0.08) Any advice would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Is this what you mean?
Click the pictures to zoom in.

If it is, you can just rotate the angles so that one of them is on angle 0.
And you now get a right triangle.

You make the following calculations:

And now just use the values of the catheti to calculate the value of the hypothenuse.
sqrt((cos(angleA) - cos(angleB))^2 + sin(angleB)^2)
You can do it with angles bigger the 90 degrees too.

Share this post


Link to post
Share on other sites
I think he only wants this :

norm = |a1 - a2|
if Norm > pi:
Result = 2 * pi - norm
else
Result = norm

This works if the angles are between -pi and pi

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!