Combining rotation quaternions

If I combine 2 rotation quaternions by multiplying them, lets say one represents some rotation around x axis and other represents some rotation around some arbitrary axis.

The order of rotation matters, so the order of the quaternion multiplication to “combine” the rotation matters also.

My question is, how does the combining of quaternion rotations work? Is it like matrix transformations, where

$$(M_2 M_1) p = M_2 (M_1 p) \, ?$$

The point $p$ will be transformed by $M_1$, and then by $M_2$, even though technically it’s just being multiplied by $M_2 M_1$. Do rotation quaternions work the same way? Does the earliest rotation have to be on the right side, and then subsequent rotations are applied by multiplying on the left?

Solutions Collecting From Web of "Combining rotation quaternions"

If you check some of the resources in the earlier question you’ll find that the most useful way quaternions act as rotations is by conjugation.

Think of the $i,j,k$ vectors as orthonormal vectors in 3-dimensional space, as we usually do in physics. Every point in 3-space then is just a linear combination of these three vectors. These are the “pure quaternions” whose real parts are 0.

Given a quaternion with norm 1, call it $u$, you can rotate a pure quaternions $v$ by conjugating: $v\mapsto uvu^{-1}$. Let $w$ be another quaternion with norm 1. Then as you observed, you can rotate by $u$ and $w$ in two different orders:

$$wuvu^{-1}w^{-1}=(wu)v(wu)^{-1}$$

or

$$uwvw^{-1}u^{-1}=(uw)v(uw)^{-1}$$

which potentially can be different.

Let’s try it with a few very simple choices of $u$ and $w$. Try $u=i$ and $w=j$, and see what happens to the $i,j,k$ vectors under those rotations. If we try this with $u=i$, you can check that $$i\mapsto iii^{-1}=i$$
$$j\mapsto iji^{-1}=-j$$ $$k\mapsto iki^{-1}=-k$$.

Visualize what has happened to the original triad $i,j,k$ after rotation. I’ll leave the other example to you.

To customize length 1 quaternions that rotate things the way you want to, you’ll have to take a look at the wiki article. Basically the idea is this: every rotation in 3-space is specified by an axis of rotation and the angle you rotate about that axis. To find your customized $u$, you first compute a unit quaternion $h$ which is normal to the plane of rotation, and then an expression like $u=\cos(\theta/2)+h\sin(\theta/2)$ turns out to be what you want. (I haven’t been careful about specifying the direction and rotation or signs in this sketch, so take care when following the detailed explanation.)

To rotate a vector $v = ix + jy + kz$ by a quaternion $q$ you compute $v^q = q v q^{-1} $.

So if $q$ and $q’$ are two rotation quaternions, to rotate by $q$ then $q’$ you calculate $(v^q)^{q’} = q’ q \,v\, q^{-1} q’^{-1} = q’ q \,v\, (q’ q)^{-1} = v^{q’q}.$


References

Quaternions and spatial rotation