Quaternions

Son: Well, Papa, can you multiply triplets?
Father: No [sadly shaking his head], I can only add and subtract them. (William Rowan Hamilton, Conversation with his sons (1843))

Quaternions are an attempt to extend complex numbers to a higher dimension. This formulation was first proposed by Sir William Rowan Hamilton. They are represented by a vector of $\mathbb{R}^{4}$ in the form of

\begin{displaymath}
\mathbf{q} = \begin{bmatrix}
q_w \\ q_x \\ q_y \\ q_z
\end{bmatrix} = q_w + q_x i + q_y j + q_z k
\end{displaymath} (A.17)

, sometimes also referred to as $\mathbf{q} = \begin{pmatrix}q_0 & q_1 & q_2 & q_3 \end{pmatrix} = \begin{pmatrix}q_1 & q_2 & q_3 & q_4 \end{pmatrix}$. Quaternions have different properties compared to ordinary four-dimensional vectors (such as homogeneous coordinates). The quaternion (A.17) can be viewed as composed of a vector part $\mathbf{v} \in \mathbb{R}^{3}$ and a scalar part $q_w$:
\begin{displaymath}
\mathbf{q} = \begin{bmatrix}
q_w \\ \mathbf{v}
\end{bmatrix}\end{displaymath} (A.18)

$q_w$ is defined as the scalar part (or real component), while $q_x,q_y,q_z$ are the vector components (or imaginary parts). A quaternion with only the scalar part is called real, while a quaternion with only the vector part is termed pure.

The product of quaternions, for example, is not commutative (but it is still associative).

It is possible to create an augmented vector (augmented vector) of a vector $\mathbf{r} \in \mathbb{R}^{3}$ in quaternion space as follows:

\begin{displaymath}
\bar{\mathbf{r}} = \begin{bmatrix}
0 \\ \mathbf{r}
\end{bmatrix}\end{displaymath} (A.19)

The conjugate of a quaternion $\mathbf{q}^{*}$ is

\begin{displaymath}
\mathbf{q}^{*} = \begin{bmatrix}
q_w \\ - \mathbf{v}
\end{bmatrix}\end{displaymath} (A.20)

The norm $\vert \mathbf{q} \vert$ is

\begin{displaymath}
\vert \mathbf{q} \vert = \sqrt{ \mathbf{q}^{*} \mathbf{q} } = \sqrt{ q_w^{2} + \mathbf{v}^{2} }
\end{displaymath} (A.21)

A quaternion $\vert\mathbf{q}\vert=1$ is called a unit quaternion. The inverse of a unit quaternion is its complex conjugate $\mathbf{q}^{-1} = \mathbf{q}^{*}$.

The most important property of a quaternion is that it represents a rotation in $\mathbb{R}^3$.

A rotation $\mathbf{R} = e^{ \vartheta \hat{\mathbf{u}} }$, expressed in axis-angle representation, can be written in quaternion form as follows:

\begin{displaymath}
\mathbf{q} = \exp(\vartheta \hat{\mathbf{u}}) =
\begin{bma...
...at{ \mathbf{u} } \sin \left( \vartheta/2 \right)
\end{bmatrix}\end{displaymath} (A.22)

with $\vartheta$ representing a rotation angle and $\hat{ \mathbf{u} }$ denoting a three-dimensional unit vector. In this case, it is a unit quaternion and represents the rotation of an angle $\vartheta$ around the axis $\hat{ \mathbf{u} }$. It is noteworthy that a rotation of $-\vartheta$ with respect to $-\hat{ \mathbf{u} }$ yields the same quaternion as the rotation of $\vartheta$ around $\hat{ \mathbf{u} }$, thus resolving the singularity of the axis/angle representation. Similarly, it is possible to define the "logarithm" of a quaternion:
\begin{displaymath}
\vartheta \hat{\mathbf{u}} = \log \mathbf{q} = \left\{
\b...
...bf{v} \neq 0 \\
0 & \mathbf{v} = 0 \\
\end{array} \right.
\end{displaymath} (A.23)

which returns the standard axis-angle representation of a rotation given a quaternion.

Rotations are represented by unit-length quaternions $\mathbf{q}^{\top}\mathbf{q}=1$.

It is possible to rotate a point using quaternions directly $\mathbf{p}' = \mathbf{q} \mathbf{p} \mathbf{q}^{-1}$, or a unit quaternion can be converted into a rotation matrix (directional cosine matrix):

\begin{displaymath}
\mathbf{R} = \begin{bmatrix}
q^{2}_w + q^{2}_x - q^{2}_y -...
...wq_x & q^{2}_w - q^{2}_x - q^{2}_y + q^{2}_z \\
\end{bmatrix}\end{displaymath} (A.24)

or equivalently:
\begin{displaymath}
\mathbf{R} = \begin{bmatrix}
1 - 2(q_y^2 + q_z^2) & 2(q_x ...
...y) & 2(q_y q_z + q_w q_x) & 1 - 2(q_x^2 + q_y^2)
\end{bmatrix}\end{displaymath} (A.25)

to subsequently compute $\mathbf{p}' = \mathbf{R} \mathbf{p}$.

It is noteworthy that $\mathbf{q}$ and $-\mathbf{q}$ represent the same rotation matrix $\mathbf{R}$.

Conversely, from the rotation matrix it is possible to derive the quaternion, for example, through

\begin{displaymath}
\begin{array}{rl}
q^{2}_w & = (r_{11} + r_{22} + r_{33} + 1...
...4 q_w) \\
q_z & = (r_{21} - r_{12}) / (4 q_w) \\
\end{array}\end{displaymath} (A.26)

(operationally, one looks for the largest component and calculates the other components with respect to that one).

The product of two quaternions ultimately represents the composition of rotations:

\begin{displaymath}
\mathbf{q} \times \mathbf{t} = \begin{bmatrix}
t_w q_w - t_...
... \\
t_w q_z - t_x q_y + t_y q_x + t_z q_w \\
\end{bmatrix}
\end{displaymath} (A.27)

Paolo medici
2025-10-22