3d – Combining Quaternion Rotations

Multiplying two quaternions gives you a quaternion equivalent to performing the two rotations they represent in sequence.

q3 = q1 * q2
q3 * object = q1 * (q2 * object) 
// "Perform rotation q2 with respect to the world axes, then q1"
// Or equivalently: "Perform rotation q1 about your local axes, then q2"

q4 = q2 * q1
q4 * object = q2 * (q1 * object)
// "Perform rotation q1 with respect to the world axes, then q2"
// Or equivalently: "Perform rotation q2 about your local axes, then q1"

(Notice that rotating around the object’s local axes – ones that spin with the object – means applying the rotations in the opposite order than if we consider our axes fixed in the world reference frame)

These two possible sequences will generally give different results from one another, and different results from a single rotation along an axis intermediate between the axes of q1 and q2, because 3D rotation is extremely order-dependent.

This isn’t just a quirk of quaternions, but something true of orientations in three-dimensional space themselves.

Our experience from translation might mislead us. With a translation like (+1, +2, +3), we can separate it into…

  • a translation by 1 unit along the x axis

  • a translation by 2 units along the y axis

  • and a translation by 3 units along the z axis

…and perform the three axis-aligned translations one at a time, in any order, and still get the same result of applying the composed translation all at once.

Rotation does not work that way, so an intuition calibrated on translation can easily lead us to false conclusions.

Comparison of order in translation vs rotation

You can verify this for yourself with the axes in your example. Grab an object with an identifiable top/right/front, and mentally map its sides to axes.

  • Place it on a table, and find an axis 45 degrees between the x and z axes you picked. Twist the object 45 degrees about that axis, and remember what that orientation looks like.

  • Now repeat the experiment, but this time rotate 45 degrees around just the x axis first, then 45 degrees about the z axis, wherever it ends up.

You’ll observe that the orientation you get at the end is different between the two experiments.

Rotation is not simply separable into axis-aligned components.

Or to be more precise: there will be many possible trios of axis-aligned rotations that give the same resulting orientation as any orientation you formed some other way (that’s how Euler angles / Tait-Bryan angles work), but there’s not such a simple mapping between the combined and separated forms like there is for translation. You can’t just take the same angle and repeat it/split it proportionally between the components of its axis and get the same result. The trigonometry of the conversion is messy and has lots of counter-intuitive edge cases. As shown in the link above, sometimes applying a rotation about x and y gives you a rotation about the z!

So, to recap: it is true that to combine rotations expressed as quaternions, all you have to do is multiply those quaternions. But that represents a specific kind of combination, which is composition: applying one rotation, then the other, in sequence.

Our intuition about what this composition should do may depart significantly from the reality, unless we spend a lot of time turning mugs around in our hands. (Just remember to finish your coffee or tea first!)