Jump to content
  • Advertisement
Sign in to follow this  

Find angle between Quaternion A and B

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

After much google-ing i found a few ways to find the angle between two quaternions that yield the same result. I picked the one that makes the most sense to me and implemented it.

float Quaternion::Angle(Quaternion& a, Quaternion& b) {
Quaternion inv = Quaternion::Inverse(a);
Quaternion res = b * inv;
return acosf(res.w) * 2.0f;// * 57.2957795f; // To degrees!;

Now, i run my test code

Quaternion q1 = Quaternion::Euler(10.0f, 5.0f, 90.0f);
Quaternion q2 = Quaternion::Euler(7.0f, -80.0f, 360.0f);
cout << Quaternion::Angle(q1, q2) << '\n';

And the result is 4.40809 radians
Not bad, i multiply it by 57.2957795f to convert it to degrees and the angle is 252.565 degrees

I compare this to Unity's implementation of the .Angle function

Quaternion q1 = Quaternion.Euler(10.0f, 5.0f, 90.0f);
Quaternion q2 = Quaternion.Euler(7.0f, -80.0f, 360.0f);
Debug.Log(Quaternion.Angle(q1, q2));

And the result is 107.4352 degrees
Odd... Multiply that by Unity's Mathf.Deg2Rad constant and the result is 1.875097 radians

So my question would be something along the lines of: "What on earth am i doing wrong?"

Share this post

Link to post
Share on other sites
You're forgetting that the quaternion angle is either N degrees rotation around the axis or -N degrees rotation around the opposite axis. If you get an angle above 180 degrees what you probably wanted is 360 degrees minus the answer you computed. Notice how your answer plus Unity's answer add up to 360 degrees.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!