• Create Account

Rotation difference between two quaternions?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

#1Hexer  Members

Posted 10 November 2006 - 07:24 AM

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.

#2Sneftel  Senior Moderators

Posted 10 November 2006 - 07:31 AM

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.

#3Hexer  Members

Posted 10 November 2006 - 07:38 AM

Quote:
 Original post by SneftelGiven 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?

#4Sneftel  Senior Moderators

Posted 10 November 2006 - 08:01 AM

Quote:
 Original post by Hexerby 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.

#5Anonymous Poster_Anonymous Poster_*  Guests

Posted 11 November 2006 - 02:26 AM

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).

#6Basiror  Members

Posted 11 November 2006 - 04:52 AM

To calculate the inverse quaternion

q
q* is the conjugate quaternion

so the inverse q^-1 = q*/(qq*)

#7Hexer  Members

Posted 11 November 2006 - 04:37 PM

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}

#8Sneftel  Senior Moderators

Posted 12 November 2006 - 04:37 AM

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.

#9Hexer  Members

Posted 12 November 2006 - 06:01 AM

got it, thanks!

#10JasonBlochowiak  Members

Posted 16 November 2006 - 08:40 AM

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.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.