Two-to-one problem

Figure 3.10: There are two ways to encode the same rotation in terms of axis and angle, using either $ v$ or $ -v$.
\begin{figure}
% latex2html id marker 3482
\centerline{\psfig{file=figs/eulertheorem2.eps,width=5.0in}}\end{figure}

Before getting to quaternions, it is important point out one annoying problem with Euler's rotation theorem. As shown in Figure 3.10, it does not claim that the axis-angle representation is unique. In fact, for every 3D rotation other than the identity, there are exactly two representations. This is due to the fact that the axis could ``point'' in either direction. We could insist that the axis always point in one direction, such as positive $ y$, but this does not fully solve the problem because of the boundary cases (horizontal axes). Quaternions, which are coming next, nicely handle all problems with 3D rotations except this one, which is unavoidable.

Quaternions were introduced in 1843 by William Rowan Hamilton. When seeing them the first time, most people have difficulty understanding their peculiar algebra. Therefore, we will instead focus on precisely which quaternions correspond to which rotations. After that, we will introduce some limited quaternion algebra. The algebra is much less important for developing VR systems, unless you want to implement your own 3D rotation library. The correspondence between quaternions and 3D rotations, however, is crucial.

A quaternion $ h$ is a 4D vector:

$\displaystyle q = (a,b,c,d),$ (3.28)

in which $ a$, $ b$, $ c$, and $ d$ can take on real values. Thus, $ q$ can be considered as a point in $ {\mathbb{R}}^4$. It turns out that we will only use unit quaternions, which means that

$\displaystyle a^2 + b^2 + c^2 + d^2 = 1$ (3.29)

must always hold. This should remind you of the equation of a unit sphere ( $ x^2+y^2+z^2=1$), but it is one dimension higher. A sphere is a 2D surface, whereas the set of all unit quaternions is a 3D ``hypersurface'', more formally known as a manifold [27,151]. We will use the space of unit quaternions to represent the space of all 3D rotations. Both have 3 DOFs, which seems reasonable.

Let $ (v,\theta)$ be an axis-angle representation of a 3D rotation, as depicted in Figure 3.9. Let this be represented by the following quaternion:

$\displaystyle q = \left( \cos \frac{\theta}{2} \;,\; v_1 \sin \frac{\theta}{2}\;,\; v_2 \sin \frac{\theta}{2}\;,\; v_3 \sin \frac{\theta}{2} \right) .$ (3.30)

Think of $ q$ as a data structure that encodes the 3D rotation. It is easy to recover $ (v,\theta)$ from $ q$:

$\displaystyle \theta = 2 \cos^{-1} a$    and $\displaystyle v = \frac{1}{\sqrt{1 - a^2}} (b, c, d) .$ (3.31)

If $ a=1$, then (3.31) breaks; however, this corresponds to the case of the identity rotation.

Figure 3.11: For these cases, you should be able to look at the quaternion and quickly picture the axis and angle of the corresponding 3D rotation.
\begin{figure}\begin{center}
\begin{tabular}{lll}
Quaternion & Axis-Angle & Desc...
...$((0,0,1),\pi/2)$ & Roll by $\pi/2$ \\
\end{tabular}\end{center}
\end{figure}

Figure 3.12: Simple relationships between equivalent quaternions and their inverses.
\begin{figure}\centerline{\psfig{file=figs/fourquats.eps,width=3.5truein}}\end{figure}

You now have the mappings $ (v,\theta) \mapsto q$ and $ q \mapsto (v,\theta)$. To test your understanding, Figure 3.11 shows some simple examples, which commonly occur in practice. Furthermore, Figure 3.12 shows some simple relationships between quaternions and their corresponding rotations. The horizontal arrows indicate that $ q$ and $ -q$ represent the same rotation. This is true because of the double representation issue shown in Figure 3.10. Applying (3.30) to both cases establishes their equivalence. The vertical arrows correspond to inverse rotations. These hold because reversing the direction of the axis causes the rotation to be reversed (rotation by $ \theta $ becomes rotation by $ 2\pi - \theta$).

How do we apply the quaternion $ h = (a,b,c,d)$ to rotate the model? One way is to use the following conversion into a 3D rotation matrix:

$\displaystyle R(h) = \begin{bmatrix}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{bmatrix} .$ (3.32)

A more efficient way exists which avoids converting into a rotation matrix. To accomplish this, we need to define quaternion multiplication. For any two quaternions, $ q_1$ and $ q_2$, let $ q_1 *q_2$ denote the product, which is defined as

\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} (3.33)

In other words, $ q_3 = q_1 * q_2$ as defined in (3.33).

Here is a way to rotate the point $ (x,y,z)$ using the rotation represented by $ h$. Let $ p = (x,y,z,1)$, which is done to give the point the same dimensions as a quaternion. Perhaps surprisingly, the point is rotated by applying quaternion multiplication as

$\displaystyle p' = q * p * q^{-1} ,$ (3.34)

in which $ q^{-1} = (a,-b,-c,-d)$ (recall from Figure 3.12). The rotated point is $ (x',y',z')$, which is taken from the result $ p' = (x',y',z',1)$.

Here is a simple example for the point $ (1,0,0)$. Let $ p = (1,0,0,1)$ and consider executing a yaw rotation by $ \pi/2$. According to Figure 3.11, the corresponding quaternion is $ q = (0,0,1,0)$. The inverse is $ q^{-1} = (0,0,-1,0)$. After tediously applying (3.33) to calculate (3.34), the result is $ p' = (0,1,0,1)$. Thus, the rotated point is $ (0,1,0)$, which is a correct yaw by $ \pi/2$.

Steven M LaValle 2016-12-31