An ordinary complex number is written as \(a+bi\) using real numbers \(a,b\) and the imaginary unit \(i\): a number system built from two independent basis elements, \(1\) and \(i\). As you know from high-school mathematics, multiplying a complex number by a unit-norm complex number \(e^{i\theta}\) produces a rotation in the complex plane — in other words, rotations in two dimensions (the plane) are represented by unit-norm complex numbers. A natural next step is to ask: can we represent three-dimensional rotations by adding one more imaginary unit to obtain a "trinion"? It turns out, as Hamilton showed, that no such three-component system can be closed under multiplication without internal contradictions1. However, with four components — quaternions — the contradictions disappear and mathematical consistency is restored. Quaternions are the algebraic structure that correctly describes rotations in three-dimensional space. This page explains the relationship between quaternions and rotation transformations.
What is a Quaternion?
A quaternion is a number system expressed using one real number and three imaginary numbers. With real numbers \(a,b,c,d\) and imaginary units \(i,j,k\), a quaternion is written as
$$a+bi+cj+dk.$$
The imaginary units satisfy
$$i^2 = j^2 = k^2 = ijk = -1,$$
from which the following multiplication rules also follow:
$$ij=k,\ ji=-k,\ jk=i,\ kj=-i,\ ki=j,\ ik=-j.$$
Note that quaternion multiplication is non-commutative: the order of multiplication matters.
Quaternion Arithmetic
Quaternion arithmetic follows the standard rules of linear algebra and is intuitive. Addition is
$$(a_1+b_1i+c_1j+d_1k) + (a_2+b_2i+c_2j+d_2k) = (a_1+a_2)+(b_1+b_2)i+(c_1+c_2)j+(d_1+d_2)k,$$
and multiplication is2
$$\begin{array}{l}
(a_1+b_1i+c_1j+d_1k)(a_2+b_2i+c_2j+d_2k) =\\
\quad a_1a_2-b_1b_2-c_1c_2-d_1d_2 +(a_1b_2+b_1a_2+c_1d_2-d_1c_2)i\\
\quad +(a_1c_2-b_1d_2+c_1a_2+d_1b_2)j + (a_1d_2+b_1c_2-c_1b_2+d_1a_2)k.
\end{array}$$
Both addition and multiplication are associative3.
Quaternions are commonly written in vector notation as
$$a+bi+cj+dk = (a,b,c,d).$$
Furthermore, the real part (one component) and the imaginary part (three components) can be written separately as a scalar \(s=a\) and a vector \(\mathbf{v}=(b,c,d)\):
$$(a,b,c,d)=(s,\mathbf{v}).$$
In this notation, addition and multiplication become
$$\begin{aligned}
(s_1,\mathbf{v}_1)+(s_2,\mathbf{v}_2) &= (s_1+s_2,\,\mathbf{v}_1+\mathbf{v}_2),\\
(s_1,\mathbf{v}_1)(s_2,\mathbf{v}_2) &= (s_1s_2-\mathbf{v}_1\cdot\mathbf{v}_2,\; s_1\mathbf{v}_2+s_2\mathbf{v}_1+\mathbf{v}_1\times\mathbf{v}_2).
\end{aligned}$$
In the following, \(s\) is called the "real part" or "scalar part", and \(\mathbf{v}\) the "imaginary part" or "vector part".
The conjugate of a quaternion is defined analogously to complex conjugation — by negating the imaginary parts:
$$Q=(a,b,c,d)=(s,\mathbf{v}) \quad\leftrightarrow\quad Q^*=(a,-b,-c,-d)=(s,-\mathbf{v}).$$
The product \(QQ^*=Q^*Q=a^2+b^2+c^2+d^2=s^2+\|\mathbf{v}\|^2\), and the norm is defined as
$$\|Q\|=\sqrt{Q^*Q}=\sqrt{QQ^*}.$$
This is simply the Euclidean distance in four-dimensional space. The multiplicative inverse of a nonzero quaternion is
$$Q^{-1}=Q^*/\|Q\|^2, \quad QQ^{-1}=Q^{-1}Q=1.$$
A quaternion with unit norm is called a unit quaternion, and for unit quaternions the conjugate equals the inverse: \(\|Q\|=1\Leftrightarrow Q^{-1}=Q^*\).
Unit Quaternions and Rotation
A unit quaternion satisfies \(a^2+b^2+c^2+d^2=1\). In particular,
$$P=\left(\cos\frac{\theta}{2},\; x\sin\frac{\theta}{2},\; y\sin\frac{\theta}{2},\; z\sin\frac{\theta}{2}\right), \quad x^2+y^2+z^2=1,$$
is a unit quaternion. Now suppose two quaternions \(A\) and \(B\) are related by conjugation with \(P\):
$$B=PAP^*.$$
Taking \(A\) to be a pure imaginary quaternion4 \((0,X,Y,Z)\), expanding and simplifying5 gives
$$B=\left(0,\;
X(x^2(1-\cos\theta)+\cos\theta)+Y(xy(1-\cos\theta)-z\sin\theta)+Z(zx(1-\cos\theta)+y\sin\theta),\right.$$
$$\left.X(xy(1-\cos\theta)+z\sin\theta)+Y(y^2(1-\cos\theta)+\cos\theta)+Z(yz(1-\cos\theta)-x\sin\theta),\right.$$
$$\left.X(zx(1-\cos\theta)-y\sin\theta)+Y(yz(1-\cos\theta)+x\sin\theta)+Z(z^2(1-\cos\theta)+\cos\theta)\right).$$
The vector part \((X’,Y’,Z’)\) is exactly the result of applying the rotation matrix from the previous page to \((X,Y,Z)\):
$$\begin{pmatrix}X’\\Y’\\Z’\end{pmatrix}=
\begin{pmatrix}
x^2(1-\cos\theta)+\cos\theta & xy(1-\cos\theta)-z\sin\theta & zx(1-\cos\theta)+y\sin\theta\\
xy(1-\cos\theta)+z\sin\theta & y^2(1-\cos\theta)+\cos\theta & yz(1-\cos\theta)-x\sin\theta\\
zx(1-\cos\theta)-y\sin\theta & yz(1-\cos\theta)+x\sin\theta & z^2(1-\cos\theta)+\cos\theta
\end{pmatrix}\begin{pmatrix}X\\Y\\Z\end{pmatrix}.$$
The vector part of \(B=PAP^*\) is the vector part of \(A\) rotated by angle \(\theta\) about the vector part \((x,y,z)\) of \(P\).
Note also that \(P\) and \(-P\) represent the same rotation, since a rotation by \(\theta\) about axis \((x,y,z)\) is identical to a rotation by \(-\theta\) about \((-x,-y,-z)\):
$$PAP^*=(-P)A(-P)^*.$$
Angular Difference between Two Unit Quaternions
Given two unit quaternions \(P\) and \(Q\), how do we find the angular difference between them (the minimum rotation angle connecting the two orientations, i.e., the misorientation)?
Let \(A\) be an arbitrary pure imaginary quaternion. Under \(P\) and \(Q\) it maps to \(PAP^*\) and \(QAQ^*\), respectively. Let \(R\) be the unit quaternion corresponding to the rotation \(P\to Q\). Then for all \(A\):
$$R(PAP^*)R^*=QAQ^*,$$
which gives \(RP=Q\), hence \(R=QP^*\). If we only need the rotation angle \(\theta\), it suffices to find the real part of \(R\) (which equals \(\cos(\theta/2)\)). Writing \(P=(a_1,b_1,c_1,d_1)\) and \(Q=(a_2,b_2,c_2,d_2)\):
$$\mathrm{Re}(QP^*)=a_1a_2+b_1b_2+c_1c_2+d_1d_2=\cos\frac{\theta}{2},$$
$$\theta=2\arccos(a_1a_2+b_1b_2+c_1c_2+d_1d_2).$$
Note the analogy with the dot product: for two unit vectors \(\vec{u}=(a_1,b_1,c_1,\ldots)\) and \(\vec{v}=(a_2,b_2,c_2,\ldots)\) enclosing angle \(\theta\), we have \(\vec{u}\cdot\vec{v}=\cos\theta\). The quantity \(\mathrm{Re}(QP^*)=a_1a_2+b_1b_2+c_1c_2+d_1d_2=\cos(\theta/2)\) is the inner product of \(P\) and \(Q\) regarded as four-dimensional vectors. The factor of 2 in the argument of cosine is the only difference — a remarkably elegant parallel6.
Distribution of Angular Differences
Let us use the properties of unit quaternions to derive the distribution of angular differences for randomly oriented objects. To make things concrete, consider an astronaut figure that is fully asymmetric (no symmetry element other than the identity).

Imagine a large number of such astronauts drifting in completely random orientations. Pick any two at random and compute the angular difference between their orientations (ignoring translations). What is the probability distribution of this angular difference?

Unit quaternions are key here. Every orientation corresponds to some unit quaternion, and if we regard unit quaternions as points on the unit 3-sphere \(S^3\) in four-dimensional space, then a uniformly random orientation corresponds to a uniformly distributed point on \(S^3\). Without loss of generality we may fix one orientation and let the other be random. The problem thus reduces to: "what is the probability of finding a point on \(S^3\) at angular distance \(\phi\) from a fixed point?" Note the relation \(\phi=\theta/2\) between the four-dimensional angle \(\phi\) and the rotation angle \(\theta\).
Pick the north pole \(P\) on \(S^3\). Points at angular distance \(\phi\) from \(P\) form a 3-sphere (a "latitude hypersphere")7 of radius \(\sin\phi\), with surface area \(4\pi\sin^2\phi\). So the misorientation distribution function \(F(\phi)\) is proportional to \(\sin^2\phi\). Since \(-P\) and \(P\) represent the same rotation, we restrict \(\phi\in[0,\pi/2]\) (the northern hemisphere). Substituting \(\phi=\theta/2\) and normalising gives:
$$\boxed{F(\theta)=\frac{1-\cos\theta}{\pi}}, \quad 0\le\theta\le\pi.$$
The figure shows the distribution with \(\theta\) in degrees. The probability of small angular differences is low, increases with \(\theta\), and reaches a gentle maximum at 180° — a result that is intuitively plausible.

- See https://qiita.com/OmojiP/items/f1d3320483462907a796 for a detailed explanation. ↩︎
- Expanding directly: \((a_1+b_1i+c_1j+d_1k)(a_2+b_2i+c_2j+d_2k)\) using \(i^2=j^2=k^2=-1\), \(ij=k\), etc. ↩︎
- For three quaternions \(A,B,C\): \((A+B)+C=A+(B+C)\) and \((AB)C=A(BC)\). ↩︎
- A quaternion with zero real part is called a pure imaginary quaternion. ↩︎
- The double-angle formulae cause the \(\theta/2\) to disappear and \(\theta\) to appear. ↩︎
- See https://kt-project.com/wp/math/number-theory/quartanion/math4-3/ for further discussion. ↩︎
- In a 3-sphere, a "latitude circle" is a 2-sphere; by analogy, a latitude hypersphere in a 4-sphere is a 3-sphere. ↩︎