Quaternions

The manner in which complex numbers were used to represent 2D rotations will now be adapted to using quaternions to represent 3D rotations. Let $ {\mathbb{H}}$ represent the set of quaternions, in which each quaternion, $ h \in {\mathbb{H}}$, is represented as $ h = a + b i + c j + d
k$, and $ a,b,c,d \in {\mathbb{R}}$. A quaternion can be considered as a four-dimensional vector. The symbols $ i$, $ j$, and $ k$ are used to denote three ``imaginary'' components of the quaternion. The following relationships are defined: $ i^2 = j^2 = k^2 = ijk = -1$, from which it follows that $ i j = k$, $ j k = i$, and $ k i = j$. Using these, multiplication of two quaternions, $ h_1 = a_1 + b_1 i + c_1 j +
d_1 k$ and $ h_2 = a_2 + b_2 i + c_2 j + d_2 k$, can be derived to obtain $ h_1 \cdot h_2= a_3 + b_3 i + c_3 j + d_3 k$, in which

\begin{displaymath}\begin{split}a_3 & = a_1 a_2 - b_1 b_2 - c_1 c_2 - d_1 d_2 \\...
...  d_3 & = a_1 d_2 + a_2 d_1 + b_1 c_2 - b_2 c_1 . \end{split}\end{displaymath} (4.19)

Using this operation, it can be shown that $ {\mathbb{H}}$ is a group with respect to quaternion multiplication. Note, however, that the multiplication is not commutative! This is also true of 3D rotations; there must be a good reason.

For convenience, quaternion multiplication can be expressed in terms of vector multiplications, a dot product, and a cross product. Let $ v
= [b \;\; c \;\; d]$ be a three-dimensional vector that represents the final three quaternion components. The first component of $ h_1 \cdot
h_2$ is $ a_1 a_2 - v_1 \cdot v_2$. The final three components are given by the three-dimensional vector $ a_1 v_2 + a_2 v_1 + v_1 \times
v_2$.

In the same way that unit complex numbers were needed for $ SO(2)$, unit quaternions are needed for $ SO(3)$, which means that $ {\mathbb{H}}$ is restricted to quaternions for which $ a^2 + b^2 + c^2 + d^2 = 1$. Note that this forms a subgroup because the multiplication of unit quaternions yields a unit quaternion, and the other group axioms hold.

Figure 4.9: Any 3D rotation can be considered as a rotation by an angle $ \theta $ about the axis given by the unit direction vector $ v = [v_1 \;\; v_2 \;\; v_3]$.
\begin{figure}\centerline{\psfig{file=figs/thetav.eps,width=1.5in}}\end{figure}

Figure 4.10: There are two ways to encode the same rotation.
\begin{figure}\centerline{\psfig{file=figs/thetav2.eps,width=3.0in}}\end{figure}

The next step is to describe a mapping from unit quaternions to $ SO(3)$. Let the unit quaternion $ h = a + b i + c j + d
k$ map to the matrix

$\displaystyle R(h) = \begin{pmatrix}2 (a^2 + b^2) - 1 & 2 (b c - a d) & 2 (b d ...
...(c d - a b)  2 (b d - a c) & 2 (c d + a b) & 2 (a^2 + d^2) - 1 \end{pmatrix},$ (4.20)

which can be verified as orthogonal and $ \det R(h) = 1$. Therefore, it belongs to $ SO(3)$. It is not shown here, but it conveniently turns out that $ h$ represents the rotation shown in Figure 4.9, by making the assignment

$\displaystyle h = \cos \frac{\theta}{2} + \left( v_1 \sin \frac{\theta}{2} \rig...
...\frac{\theta}{2} \right) \, j + \left( v_3 \sin \frac{\theta}{2} \right) \, k .$ (4.21)

Unfortunately, this representation is not unique. It can be verified in (4.20) that $ R(h) = R(-h)$. A nice geometric interpretation is given in Figure 4.10. The quaternions $ h$ and $ -h$ represent the same rotation because a rotation of $ \theta $ about the direction $ v$ is equivalent to a rotation of $ 2 \pi
- \theta$ about the direction $ -v$. Consider the quaternion representation of the second expression of rotation with respect to the first. The real part is

$\displaystyle \cos\left(\frac{2 \pi - \theta}{2}\right) = \cos\left(\pi - \frac{\theta}{2}\right) = -\cos\left(\frac{\theta}{2}\right) = -a.$ (4.22)

The $ i$, $ j$, and $ k$ components are

$\displaystyle - v \sin\left(\frac{2 \pi - \theta}{2}\right) = - v \sin\left(\pi...
...eta}{2}\right) = - v \sin\left(\frac{\theta}{2}\right) = [ -b \;\; -c \;\; -d].$ (4.23)

The quaternion $ -h$ has been constructed. Thus, $ h$ and $ -h$ represent the same rotation. Luckily, this is the only problem, and the mapping given by (4.20) is two-to-one from the set of unit quaternions to $ SO(3)$.

This can be fixed by the identification trick. Note that the set of unit quaternions is homeomorphic to $ {\mathbb{S}}^3$ because of the constraint $ a^2 + b^2 + c^2 + d^2 = 1$. The algebraic properties of quaternions are not relevant at this point. Just imagine each $ h$ as an element of $ {\mathbb{R}}^4$, and the constraint $ a^2 + b^2 + c^2 + d^2 = 1$ forces the points to lie on $ {\mathbb{S}}^3$. Using identification, declare $ h \sim -h$ for all unit quaternions. This means that the antipodal points of $ {\mathbb{S}}^3$ are identified. Recall from the end of Section 4.1.2 that when antipodal points are identified, $ {\mathbb{RP}}^n
{ \;\cong\; }{\mathbb{S}}^n {/\sim}$. Hence, $ SO(3) { \;\cong\; }{\mathbb{RP}}^3$, which can be considered as the set of all lines through the origin of $ {\mathbb{R}}^4$, but this is hard to visualize. The representation of $ {\mathbb{RP}}^2$ in Figure 4.5 can be extended to $ {\mathbb{RP}}^3$. Start with $ (0,1)^3 \subset {\mathbb{R}}^3$, and make three different kinds of identifications, one for each pair of opposite cube faces, and add all of the points to the manifold. For each kind of identification a twist needs to be made (without the twist, $ {\mathbb{T}}^3$ would be obtained). For example, in the $ z$ direction, let $ (x,y,0) \sim (1-x,1-y,1)$ for all $ x,y \in [0,1]$.

One way to force uniqueness of rotations is to require staying in the ``upper half'' of $ {\mathbb{S}}^3$. For example, require that $ a \geq 0$, as long as the boundary case of $ a = 0$ is handled properly because of antipodal points at the equator of $ {\mathbb{S}}^3$. If $ a = 0$, then require that $ b \geq 0$. However, if $ a=b=0$, then require that $ c \geq 0$ because points such as $ (0,0,-1,0)$ and $ (0,0,1,0)$ are the same rotation. Finally, if $ a=b=c=0$, then only $ d=1$ is allowed. If such restrictions are made, it is important, however, to remember the connectivity of $ {\mathbb{RP}}^3$. If a path travels across the equator of $ {\mathbb{S}}^3$, it must be mapped to the appropriate place in the ``northern hemisphere.'' At the instant it hits the equator, it must move to the antipodal point. These concepts are much easier to visualize if you remove a dimension and imagine them for $ {\mathbb{S}}^2 \subset {\mathbb{R}}^3$, as described at the end of Section 4.1.2.

Steven M LaValle 2020-08-14