Sign in to follow this  
fboy

difference between two angles

Recommended Posts

fboy    122
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
xor    516
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
rolkA    116
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this