Rotational Difference Between Two Quaternions?

Miscellaneous Forums/General Discussion/Rotational Difference Between Two Quaternions?

Like the topic says, I'm trying to find a way to calculate the rotational difference between two quaternions. I've googled for a while but all I've found so far is several closed source products which have the functionality built in.

I should probably get round to buying that 3d Maths Primer book, but in the meantime, any ideas?

Let's say p and q are quaternions.

By 'rotational difference' I guess you mean a quaternion that will turn p into q.

I will use p' to denote the inverse of p. This is the same as p, but with the x,y,z part negated. The angle is the same, but the axis points the opposite way.

p followed by p' is the identity, i.e. it does nothing. The quaternion consisting of p' followed by q does the trick. When applied to p it first turns p into the identity, and from there goes to q.

Ok, so if I've understood you correctly, you're saying something like this? :

QuatDiff.X=-Quat1.X+Quat2.X
QuatDiff.Y=-Quat1.Y+Quat2.Y
QuatDiff.Z=-Quat1.Z+Quat2.Z


What about W?

No, I'm saying you need a quaternion which is the inverse of p. This time I will call it pInv.
pInv.w = p.w
pInv.x = -p.x
pInv.y = -p.y
pInv.z = -p.z

Remember that this encodes angle and axis. Imagine that you and I are facing each other. There is a wheel between us, with its rotational axis ( axle ) on the line connecting us. You turn the wheel 10 degrees clockwise. I then do the same, but clockwise is from my point view facing the opposite way. The wheel goes back to where it began, so our turns are inverses of each other.

You 'compose' quaterions by multiplying them. Consider what (pInv * q) does when applied to p.

p * (pInv * q) is the same as (p * pInv) * q, which is just q because p and pInv cancel each other.

Doh sorry, I already knew that quaternion rotations were composed by multiplying them, but I obviously had a bit of brainfart there for a minute and forgot. Oh I'll just blame it on this heavy cold which has been kicking my arse all day. Thanks, I think I got it now.

I don't understand anything you just said, but I have used quaternions a bit, and if I wanted to know how far apart the two rotations were seperated, I would transform a normal with each of them, and then do a dot product on the normals.

But maybe that's not what you meant by rotational difference.