[Math] Quaternions multiplication order (to rotate & unrotate)

inversequaternions

Say, I have parent object rotation quaternion Qp & child object rotation (local – relative to parent) quternion Qch.

1) Which order should I multiply them to get child object world(total) rotation QW?
QW = Qp * Qch or QW = Qch * Qp ? And what geometric interpretation of this order – same or reverse order of rotation execution?

2) And one more question: If I already have result total rotation of child object QW (calculated in proper way (see #1), I also know Qp & want to calculate Qch. Which order should I multiply Qp.Inverse & QW ?

3) And last – if we have situation #2, but opposite: QW & Qch are known, & Qp we need to get, what order of QW & Qch.Inverse multiplication should we use?

Thanks a lot!

Best Answer

I'll assume the convention used in this earlier answer and this earlier answer about the use of quaternions for rotation, that is, for an initial object vector $v$ and total rotation quaternion $q_w$ you get the rotated object vector by multiplying $q_w v q_w^{-1}.$

Part 1

Suppose you have a "parent" rotation with quaternion $q_p,$ and you want to combine this with a "child" rotation with quaternion $q_c$ that will rotate an object relative to the object's orientation after the "parent" rotation was performed.

Multiplication by quaternions in the conventional way transforms the world coordinates of whatever object you apply it to. In order to achieve the effect of first performing the parent rotation, then performing the child rotation relative to the rotated coordinate system that resulted from the "parent" rotation, you should apply the "child" rotation first in world coordinates.

Using the convention $q_w v q_w^{-1},$ whichever quaternion is on the right when we compute $q_w$ is the rotation that is performed first, so you want $q_w = q_p q_c.$ That way, when you compute $q_w v q_w^{-1},$ it is actually $$ q_w v q_w^{-1} = (q_p q_c) v (q_p q_c)^{-1} = (q_p q_c) v (q_c^{-1} q_p^{-1}) = q_p (q_c v q_c^{-1}) q_p^{-1}. $$

Part 2

If you have the total rotation quaternion $q_w$ and you also know the parent rotation quaternion $q_p,$ to recover the child rotation quaternion you can multiply on the left by $q_p^{-1},$ because then $$ q_p^{-1} q_w = q_p^{-1} (q_p q_c) = (q_p^{-1} q_p) q_c = q_c. $$

Part 3

If you have the total rotation quaternion $q_w$ and you also know the child rotation quaternion $q_c,$ to recover the parent rotation quaternion you can multiply on the right by $q_c^{-1},$ because then $$ q_w q_c^{-1} = (q_p q_c) q_c^{-1} = q_p (q_c^{-1} q_c) = q_p. $$

Checking the algorithm

After constructing a set of formulas like this, it's a good policy to verify that you put them together properly by taking some examples of "object" vectors and applying some examples of rotations to them.

A nice simple example is a parent rotation of $\frac\pi2$ ($90$ degrees) around the $z$ axis that takes points on the positive $x$ axis to points on the positive $y$ axis, and a child rotation of $\frac\pi2$ ($90$ degrees) around the $x$ axis that takes points on the positive $y$ axis to points on the positive $x$ axis. If you perform the parent rotation first, then perform the child rotation relative to the result of the parent rotation, the parent rotation will leave the $z$ axis where it was, but the child rotation will be about the $y$ axis in world coordinates (because that's the rotated position of the original $x$ axis), so it will take points on the positive $z$ axis to the positive $x$ axis. If you apply these rotations to a point on the positive $z$ axis and it ends up somewhere other than the positive $x$ axis, you will know you need to fix your implementation of the rotations somehow.

You can look at the rotated positions of some vectors after any one of the rotations in question (the parent rotation alone, the child rotation alone, or the combined parent-child rotation) to verify that each one is doing what you expect.

Related Question