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-dimensional space. This formulation was first proposed by Sir William Rowan Hamilton. They are represented by a vector of $\mathbb{R}^{4}$ in the form

\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.18)

sometimes also denoted $\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 from ordinary four-dimensional vectors (as are, for example, homogeneous coordinates). The quaternion (A.18) can be viewed as consisting 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.19)

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

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

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

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

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

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

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.22)

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 as a quaternion

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

where $\vartheta$ is an angle of rotation and $\hat{ \mathbf{u} }$ is a three-dimensional unit vector. In this case, it is a unit quaternion and represents a rotation through an angle $\vartheta$ about the axis $\hat{ \mathbf{u} }$. Note that a rotation of $-\vartheta$ with respect to $-\hat{ \mathbf{u} }$ yields the same quaternion as a rotation of $\vartheta$ about $\hat{ \mathbf{u} }$, 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.24)

which returns the usual 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 directly using quaternions $\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.25)

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.26)

in order to then compute $\mathbf{p}' = \mathbf{R} \mathbf{p}$.

It should be noted that $\mathbf{q}$ and $-\mathbf{q}$ represent the same rotation matrix $\mathbf{R}$: the space of three-dimensional rotations $SO(3)$ is not represented bijectively by $S^3$, but by $S^3$ with antipodal identification.

Conversely, the quaternion can be obtained from the rotation matrix, 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.27)

(operationally, the largest component is sought and the other components are computed with respect to it).

Finally, the product of two quaternions 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.28)

Paolo medici
2026-10-01