All the nuts and bolts needed to go from quaternions to a quaternion rotation operator
Citation Note: I have borrowed this article’s content from Jack B. Kuipers’ seminal 1999 book
on quaternions.
As an admirer of the book’s writing style, I submit that you are probably better off referring to Chapter 5 of the book. My motivation to write this regardless is twofold - to provide robotics practitioners with a one-stop-shop entry point to quaternions and challenge/improve my understanding of them. I claim no expertise in this topic but found it so fascinating that I decided to write about it.
Prerequisites: This is [2/3] article in my series on quaternions. For this article, I assume readers’ familiarity with basic quaternion algebra
and rotation matrices and their basic properties .
After going back and forth about it in my mind, I have decided to write about the quaternion rotation operator in two parts:
At the cost of clarity, I am probably risking losing readers’ attention and I only hope to keep you interested enough to stay aboard till the end of the series.
As we know, rotation matrices are \(3 \times 3\) orthogonal matrices with determinant 1 (unimodular). In fact, one can use any \(3 \times 3\) matrix \(R\) that satisfies the orthogonality and the unimodularity
And more importantly, similar to rotation matrices, the operator \(R_{\mathbf{q}}\) should somehow bring about a notion of an axis and an angle of rotation to it. Of course the quaternion operator should also be able to reproduce other properties such as sequence of rotations i.e., have an equivalent form of \(R_1R_2R_3\vec{v}\), say \(R_{\mathbf{q}_1\mathbf{q}_2\mathbf{q}_3}\) and reverse rotations (e.g. \(R_1^{-1}R_2R_3\vec{v}\)) and more.
Perhaps we’ll worry about them later but at its core, it appears that the four fundamental desirable qualities of rotation operator \(R_{\mathbf{q}}\) are as follows:
By the end of this article, we will see that this checklist is indeed fulfilled with quaternions albeit with some upgrades.
How can quaternions which are in \(\mathbb{R}^4\) operate on vectors in \(\mathbb{R}^3\)? Thanks to the Scalar + Vector model we discussed in
provide a one-to-one correspondence between \(\mathbb{R}^3\) and \(Q_0\). This is great and goes toward items 1 and 2 on our checklist.
However, multiplication (See Eq. \((1)\) from
It is now clear that quaternion multiplication allows us to operate on vectors, as one should expect if one wants to define an \(\mathbb{R}^3\) rotation operator based on quaternions.
Item 1 in the list is checked. Quaternions can indeed operate on vectors, a.k.a pure quaternions, in a rather straightforward way.
For quaternions to operate on vectors in \(\mathbb{R}^3\), it would have helped a lot in favour of item 2 in our list if their multiplication led to a one-to-one correspondence between \(\mathbb{R}^3\) and \(Q_0\). However, we see in Eq. \(\text{(1)}\) that the double product still has a scalar part. This is why the double products \(\mathbf{q} \star \mathbf{v}\) and \(\mathbf{v} \star \mathbf{q}\)
As one should, let us see if a triple product gives us what we want and what we want is to be able to stay in \(\mathbb{R}^3\) after the multiplication. Consider two general quaternions \(\mathbf{p}=p_0 + \vec{p}\) and \(\mathbf{q} = q_0 + \vec{q}\) and a pure quaternion \(\mathbf{v} = 0 + \vec{v}\). There are six possible products involving these three quaternions:
\[\begin{aligned} &\mathbf{p} \star \mathbf{q} \star \mathbf{v} \quad \mathbf{q} \star \mathbf{v} \star \mathbf{p} \quad \mathbf{v} \star \mathbf{p} \star \mathbf{q} \\ &\mathbf{q} \star \mathbf{p} \star \mathbf{v} \quad \mathbf{p} \star \mathbf{v} \star \mathbf{q} \quad \mathbf{v} \star \mathbf{q} \star \mathbf{p} \end{aligned}\]On examination, we see that all products where \(\mathbf{p}\) and \(\mathbf{q}\) are together lead to the same problem we discussed earlier. Their product, regardless of the order, would return another general quaternion, making them double products. Our last hope seems to be in the two leftover triple products
Despite the uninteresting exercise, lets expand the triple products, say \(\mathbf{p} \star \mathbf{v} \star \mathbf{q}\).
\[\begin{aligned} \mathbf{p} \star \mathbf{v} \star \mathbf{q} &= (\mathbf{p} \star \mathbf{v}) \star \mathbf{q} \\ &= (-\vec{p}\cdot\vec{v} + p_0\vec{v} + \vec{p} \times \vec{v}) \star \mathbf{q} \\ &= - q_0 \vec{p}\cdot\vec{v} - (p_0\vec{v} + \vec{p} \times \vec{v}) \cdot \vec{q} + (-\vec{p}\cdot\vec{v})\cdot\vec{q} \\ &\quad + q_0(p_0\vec{v} + \vec{p} \times \vec{v}) + (p_0\vec{v} + \vec{p} \times \vec{v}) \times \vec{q} \\ &= - q_0 (\vec{p}\cdot\vec{v}) - p_0(\vec{v} \cdot \vec{q}) - (\vec{p} \times \vec{v}) \cdot \vec{q} \\ & \quad - (\vec{p}\cdot\vec{v})\cdot\vec{q} + q_0(p_0\vec{v} + \vec{p} \times \vec{v}) \\ & \quad + (p_0\vec{v} + \vec{p} \times \vec{v}) \times \vec{q} \end{aligned}\]Separating out the scalar part from above, we have:
\[- q_0 (\vec{p}\cdot\vec{v}) - p_0(\vec{v} \cdot \vec{q}) - (\vec{p} \times \vec{v}) \cdot \vec{q}\]We may rewrite this with a little bit of vector algebra trickery as:
\[- q_0 (\vec{p}\cdot\vec{v}) - p_0(\vec{v} \cdot \vec{q}) + (\vec{p} \times \vec{q}) \cdot \vec{v}\]Recall that if this triple product were to be inside \(R_{\mathbf{q}}\), it should output a pure quaternion. So we have to choose \(\mathbf{p}\) and \(\mathbf{q}\) such that the scalar part goes to \(0\) for all pure quaternions. Examining the cross product term, we see that \((\vec{p} \times \vec{q}) \cdot \vec{v}\) would go to \(0\) if \(\mathbf{p}\) and \(\mathbf{q}\) are parallel to each other i.e., if \(\mathbf{p} = k\mathbf{q}\) for non-zero \(k\) since we are dealing with non-zero vectors \(\vec{p}\) and \(\vec{q}\)
It is easy to verify that the above expression goes to \(0\) when \(\vec{q}\) and \(\vec{v}\) are parallel to each other or if \(k=-1\) and \(p_0 = q_0\) which would simply mean that
\[\mathbf{p} = p_0 + \vec{p} = q_0 -\vec{q} \Rightarrow \mathbf{p} = \mathbf{q}^{\ast}\]From this discussion, we obtain two triple quaternion products that always output a pure quaternion whenever they sandwich (hence the name) a pure quaternion, although it is not yet clear how they differ from each other
\[\mathbf{q} \star \mathbf{v} \star \mathbf{q}^{\ast} \quad \quad \mathbf{q}^{\ast} \star \mathbf{v} \star \mathbf{q}\]The algebraic action of \(\mathbf{w} = \mathbf{q} \star \mathbf{v} \star \mathbf{q}^{\ast}\) is illustrated in the figure below.
A natural question to raise is - what geometric interpretation can we give this sandwich product? I study their geometric considerations more closely in my next article
Item 2 in the list is checked as long as \(R_{\mathbf{q}}\) has sandwich product.
Unit quaternions i.e., \(\Vert \mathbf{q} \Vert^2 = (\mathbf{q}^{\ast} \star \mathbf{q}) = (\mathbf{q} \star \mathbf{q}^{\ast}) = 1\) are simply quaternions whose norm is 1. What is worth noting about unit quaternions is that their quaternion multiplication preserves membership in the \(\mathbf{S}^3\) space
Perhaps this is already obvious (from Eq. \((4)\) and Eq. \((5)\) of
In fact, even for higher-order multiplication with unit quaternions, we see that the norm of the factors is preserved. Say, we have \(n\) unit quaternions \(\{\mathbf{q}_1, \mathbf{q}_2, ..., \mathbf{q}_n\}\) and a general quaternion \(\mathbf{p}\). The squared norm of their products in any order yields the same, as follows:
\[\begin{aligned} \Vert \mathbf{q}_1 \star ... \star \mathbf{p} \star ... \star \mathbf{q}_n \Vert^2 &= \Vert \mathbf{p} \star \mathbf{q}_1 \star ... \star \mathbf{q}_n \Vert^2 \\ &= \Vert \mathbf{q}_1 \star ... \star \mathbf{q}_n \star \mathbf{p} \Vert^2 \\ &= \Vert \mathbf{p} \Vert^2 \end{aligned}\]Item 3 in the list is checked as long as the \(\mathbf{q}\) in \(R_{\mathbf{q}}\) is a unit quaternion.
Complex numbers
Now, we see that the following holds:
\[\begin{aligned} z &= a + ib \\ &= r \cos \theta + i (r \sin \theta) \\ &= r (\cos \theta + i \sin \theta) \end{aligned}\]Consequently, one can obtain the complex conjugate by simply replacing \(\theta\) with \(-\theta\), i.e.,
\[\begin{aligned} z^{\ast} &= r (\cos (-\theta) + i \sin (-\theta)) \\ &= r(\cos \theta - i \sin \theta) \end{aligned}\]It helps to know that one can extend this to quaternions and write them in polar form just as well.
The complex polar form allows us to spot a special property inherent to complex numbers. Consider two complex numbers:
\[\begin{aligned} z_1 &= r_1(\cos \theta_1 + i \sin \theta_1)\\ z_2 &= r_2(\cos \theta_2 + i \sin \theta_2) \end{aligned}\]Their complex multiplication is as follows:
\[\begin{aligned} z_1z_2 &= r_1(\cos \theta_1 + i \sin \theta_1) . r_2(\cos \theta_2 + i \sin \theta_2) \\ &= r_1r_2(\cos \theta_1 \cos \theta_2 + i \cos \theta_1 \sin \theta_2 + i \sin \theta_1 \cos \theta_2 \\ & \quad - \sin \theta_1 \sin \theta_2) \\ &= r_1r_2(\cos \theta_1 \cos \theta_2 - \sin \theta_1 \sin \theta_2 \\ &\quad + i (\cos \theta_1 \sin \theta_2 + \sin \theta_1 \cos \theta_2)) \\ &= r_1r_2(\cos (\theta_1 + \theta_2) + i \sin (\theta_1 + \theta_2)) \end{aligned}\]The geometric interpretation of the complex product is clear now. When two complex numbers are multiplied, you notice that the output complex number has an associated angle that is exactly the sum of angles associated with the multiplicands and has a magnitude equal to the product of magnitudes of the multiplicands.
We can also verify that multiplying a complex number with another complex number’s conjugate essentially subtracts or cancels the former’s angle by latter’s angle. All of this is quite suggestive that complex numbers can be used to represent 2D rotations (also scaling for non-unit complex numbers), which is perhaps obvious or well-known to many. However, does this extend to quaternions? Yes. No. Maybe. We hope to find out soon!
Quaternions, particularly unit quaternions, can also be written in polar form, albeit the interpretation of the angle \(\theta\) may not be as straightforward as it is for complex numbers. We know that a unit quaternion \(\mathbf{q} = q_0 + \vec{q}\) has norm 1 i.e., \(q_0^2 + \Vert \vec{q} \Vert^2 = 1\). And that for any angle \(\theta\), we know that \(\cos^2 \theta + \sin^2 \theta = 1\) holds. So there must be an angle \(\theta\) such that
\[\begin{aligned} \cos^2 \theta &= q_0^2 \\ \sin^2 \theta &= \Vert \vec{q} \Vert^2 \end{aligned}\]The angle \(\theta\) can be defined uniquely as long as it stays within \((-\pi, \pi]\). But this is it, we now have an angle (although still unclear what it represents) associated with the quaternion \(\mathbf{q}\). We can take this form further by defining a unit vector \(\vec{u}\), which represents the direction of \(\vec{q}\):
\[\vec{u} = \frac{\vec{q}}{\Vert \vec{q} \Vert} = \frac{\vec{q}}{\sin \theta}\]Then, we may be able to write all unit quaternions in terms of the associated angle \(\theta\) and the unit vector \(\vec{u}\) as
\[\mathbf{q} = q_0 + \vec{q} = \cos \theta + \vec{u} \sin \theta\]Note, similar to complex numbers, for a quaternion expressed in this form, substituting \(-\theta\) for \(\theta\) (whatever geometric meaning the angle \(\theta\) might have) we get the complex conjugate of \(\mathbf{q}\). Which is,
\[\begin{aligned} \mathbf{q}^{\ast} &= \cos (-\theta) + \vec{u} \sin (-\theta) \\ &= \cos \theta - \vec{u} \sin \theta \end{aligned}\]It is not too difficult to verify that if we replace \(\theta\) by \(-\theta\) of \(\mathbf{q}\) in one sandwich product, we get the other one out. So by the appropriate choice of the angle \(\theta\) these operators may, in fact, represent the same geometric transformation. I discuss more of this in
I hope you will have figured out where I am going with this by now. Consider two unit quaternions:
\[\begin{aligned} \mathbf{q}_1 &= \cos \theta_1 + \vec{u} \sin \theta_1\\ \mathbf{q}_2 &= \cos \theta_2 + \vec{u} \sin \theta_2 \end{aligned}\]The quaternion product of these two (see \((1)\) in
Once again, very similar to complex numbers, this is an interesting result and has an important geometric implication. It says if we multiply two unit quaternions \(\mathbf{q}_1\) and \(\mathbf{q}_2\), each having the same unit vector \(\vec{u}\) in them, then the product is also a unit quaternion having this same unit vector \(\vec{u}\). And, associated with it is an angle that is exactly the sum of angles associated with \(\mathbf{q}_1\) and \(\mathbf{q}_2\). If, in fact, the quaternion rotation operator represents rotation, this property suggests that there is a possibility of sequencing rotations with different \(\mathbf{q}\)s, a property enjoyed by the rotation matrices.
Item 4 in the list is checked as we showed that it is possible to associate an angle \(\theta\) with unit quaternions.
We looked at some quaternion tricks, upgrades and forms that allow us to go from a 4-tuple vector with seemingly arbitrary product rules to a 3D rotation operator. We defined a checklist at the beginning and I would like to think that I convinced you that quaternions indeed meet all of them without room for doubt
and that it is in some way related to rotations in \(\mathbb{R}^3\). However, I accept that there is still a lot to be discussed and investigated, especially the geometric effects of the sandwich product when applied to an arbitrary \(\mathbb{R}^3\) vector. I wrote about exactly this in the next article of this series