Rotation difference between two quaternions?

Started by
8 comments, last by JasonBlochowiak 17 years, 5 months ago
I am trying to implement a delta-compression technique for key-framed skeletal animation exporter. The way it will work is: if the rotation difference between two key-frames of a joint is small enough, it drops the key-frame. the problem: given two quaternions how do I derive a scalar value that represents the difference between the two rotations? the quaternions can represent two completely arbitrary rotations. the animation system will use SLERP One way I could do this is by converting the quaternion to a matrix but I would like to find a shorter and more elegant way if possible.
Advertisement
Given quaternions q1 and q2 representing two orientations, the quaternion q' = q-1q2 is the rotation that will rotate from the q1 orientation to the q2 orientation. Once you have q', you can simply convert q' to an axis-angle representation and look at its angle.
Quote:Original post by Sneftel
Given quaternions q1 and q2 representing two orientations, the quaternion q' = q-1q2 is the rotation that will rotate from the q1 orientation to the q2 orientation. Once you have q', you can simply convert q' to an axis-angle representation and look at its angle.



Thanks that helps. A couple of questions..

by q' = q-1q2
you mean q' = q1-1q2 ?

and
if the axis of q1 is different from the axis of q2 (in addition to the rotation), what would the axis of q' represent?

Quote:Original post by Hexer
by q' = q-1q2
you mean q' = q1-1q2 ?

Er, yes. Sorry.

Quote:if the axis of q1 is different from the axis of q2 (in addition to the rotation), what would the axis of q' represent?

"Whatever it has to". For (almost) any two orientations, there is exactly one minimal rotation between them. If the first orientation was "looking up" and the second orientation was "looking down", then the rotation between them would be a rotation around the X axis. If the first orientation was "looking up" and the second orientation was "looking to the left", then the axis would be something complicated and hard to visualize which would nevertheless rotate a looking-up object to be looking to the left. You've correctly identified that if q1 and q2 can be represented as rotations around the same axis then q' will also be around that axis, but that's the special case.
A quaternion is just a special type of vector. Usually, you can get the angle between two unit vectors by using the dot product which would give you the cosine of the angle. If we look at the rotations that are represented by the quaternions, then we see that the unit quaternions form a double cover over the rotation space (so q = -q). Therefore, we need to do some extra work to get the correct angle between two rotations represented by quaternions, but the dot product still works. The difference in rotation (angle) between two quaternions can be given by:

angle = 2 * acos(|q1.q2|)

If you don't want to use acos, you can just use the absolute dot product itself (which is close to one for small angles).
To calculate the inverse quaternion

q
q* is the conjugate quaternion

so the inverse q^-1 = q*/(qq*)
http://www.8ung.at/basiror/theironcross.html
Thanks everyone, here is what I ended up doing and it seems to work, although not sure if it's correct. I'll test the other techniques you presented too and see if there is any improvement.

Given two quaternions q1 and q2I convert both to axis/angleaxis1, axis2, angle1, angle2theta1 = angle2 - angle1; // difference between two rotation anglestheta2 = acos(axis1 dot axis2); // angle between two rotation axesif( (theta1 + theta2) < threshold) {    // the difference is too small, drop the keyframe}
No, that's very wrong. Consider q1= a rotation of 1 degree about the X axis, and q2= a rotation of 1 degree about the Y axis. theta1=0, and theta2=90 degrees, so unless your threshhold is over 90 degrees that'll be falsely marked as a keyframe to keep.
got it, thanks!
I don't think I'd take that basic approach to animation compression. Why? Well, usually there's a higher variance in animation range between axes than there is across a given bone. For example, elbows rotate very much around one axis, but not very much across others - if you were to either have all axes keyed or zero axes keyed, you'd miss out on an opportunity for compression.

I'd recommend you take a look at axis independent curve fitting for Eulers, and transform those into quats at runtime.

This topic is closed to new replies.

Advertisement