Quaternion Representation of Rotations

 Ordinary complex numbers are expressed using real numbers \(a,b\) and the imaginary unit \(i\) as \(a+bi\). This is a number system built from two independent elements: the real number \(1\) and the imaginary unit \(i\). You may recall from high school mathematics that multiplying a complex number \(a+bi\) by a complex number \(e^{i\theta}\) with unit norm (distance from the origin in the complex plane) results in a rotation about the origin. In other words, rotations in a plane (2 dimensions) can be represented by complex numbers with unit norm. It is then natural to wonder: if we add one more element (imaginary unit) to create a three-element number system, could we represent rotations in 3 dimensions? However, through the research of the great mathematician Hamilton, it was discovered that the algebraic structure of three-element numbers leads to contradictions in multiplication and cannot form a closed number system1, and furthermore that quaternions resolve these contradictions and maintain mathematical consistency. Quaternions are the algebraic structure that properly describes 3-dimensional space. Here, we explain the relationship between quaternions and rotational transformations.

What Are Quaternions

 A quaternion is a number system that represents numbers using one real number and three imaginary numbers. Using real numbers \(a,b,c,d\) and imaginary units \(i,j,k\), it is expressed as$$a+bi+cj+dk$$

The imaginary units \(i,j,k\) satisfy the following identities:$$ i^2 = j^2 = k^2 = i j k = -1$$This is, in fact, their definition. From this, we can also derive:$$ij=k, ji=-k, jk=i, kj=-i, ki=j, ik=-j$$Note that the operations are non-commutative (the result depends on the order of computation).

Operations on Quaternions

 Operations between quaternions follow the usual rules of linear algebra and are intuitive. Namely, addition is given by$$
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 is given by$$ \begin{array}{l}
(a_1+b_1i+c_1j+d_1k)(a_2+b_2i+c_2j+d_2k)= \\
\ 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
+(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}
$$2. Both addition and multiplication satisfy the associative law3.

 It is common to write quaternions in vector notation as$$a+bi+cj+dk=(a,b,c,d)$$Furthermore, the real part (one component) and imaginary part (three components) can be written separately as a scalar quantity \(s = a\) and a vector quantity \(\textbf{v}=(b,c,d)\), giving$$(a,b,c,d)=(s, \textbf{v})$$Using this notation, addition and multiplication of quaternions can be expressed as$$
(s_1, \textbf{v}_1)+(s_2, \textbf{v}_2)=(s_1+s_2, \textbf{v}_1+\textbf{v}_2)\\
(s_1, \textbf{v}_1)(s_2, \textbf{v}_2)=(s_1s_2-\textbf{v}_1\cdot\textbf{v}_2, s_1\textbf{v}_2+s_2\textbf{v}_1+\textbf{v}_1\times\textbf{v}_2)$$Hereafter, we will refer to \(s\) as the “real part” or “scalar” of the quaternion, and \(\textbf{v}\) as the “imaginary part”, “imaginary vector”, or simply “vector”.

 The conjugate of a quaternion is defined, as with ordinary complex numbers, by negating the imaginary parts. That is, for a quaternion \(Q\), its conjugate \(Q^*\) is$$Q =(a,b,c,d)=(s, \textbf{v}) \quad \leftrightarrow \quad Q^* =(a,-b,-c,-d)=(s, -\textbf{v}) $$The product of \(Q\) and \(Q^*\) is$$Q Q^* =Q^* Q =a^2+b^2+c^2+d^2=s^2+\|\textbf{v}\|^2$$and the square root of this is defined as the norm$$\|Q\|= \sqrt{Q^* Q} = \sqrt{Q Q^*}$$In essence, this is the distance in 4-dimensional space. The inverse of a non-zero quaternion is defined as$$Q^{-1}=Q^*/\|Q\|^2$$which is always uniquely determined, and satisfies$$ Q Q^{-1} = Q^{-1} Q =1$$A quaternion with unit norm is called a unit quaternion, and the conjugate of a unit quaternion is also its inverse. That is,$$\|Q\|=1 \quad \leftrightarrow \quad Q^{-1}=Q^*$$

Unit Quaternions and Rotational Transformations

 A unit quaternion is a quaternion with unit norm (length in complex 4-dimensional space), as defined below:$$ (a, b, c, d) \quad \textrm{where} \ a^2+b^2+c^2+d^2=1$$

Then the following quaternion \(P\), obtained by substituting symbols, is naturally also a unit quaternion:$$
P=(\cos\frac{\theta}{2}, x\sin\frac{\theta}{2}, y\sin\frac{\theta}{2}, z\sin\frac{\theta}{2}), \quad \textrm{where} \ x^2+y^2+z^2=1
$$Now consider two quaternions \(A, B\) that are conjugate with respect to this unit quaternion \(P\):$$B=PAP^*$$Furthermore, let \(A\) be a quaternion with zero real part4, i.e., \( (0, X,Y,Z)\). Writing out the expression gives$$
B=(\cos\frac{\theta}{2}, x\sin\frac{\theta}{2}, y\sin\frac{\theta}{2}, z\sin\frac{\theta}{2})\ (0,X,Y,Z)\ (\cos\frac{\theta}{2}, -x\sin\frac{\theta}{2}, -y\sin\frac{\theta}{2}, -z\sin\frac{\theta}{2})
$$(where the juxtaposed quaternions are computed using the multiplication rules). Computing this5 yields$$\begin{array}{l}B=(0,\\
\qquad\ X\cos\theta +(yZ-zY)\sin\theta + x(xX+yY+zZ)(1-\cos\theta),\\
\qquad\ Y\cos\theta +(zX-xZ)\sin\theta + y(xX+yY+zZ)(1-\cos\theta),\\
\qquad\ Z\cos\theta +(xY-yX)\sin\theta + z(xX+yY+zZ)(1-\cos\theta) \quad)\\
\quad=(0,\\
\qquad\ X(x^2(1-\cos\theta) + \cos\theta) +Y(x y(1-\cos\theta) – z\sin\theta)+Z(zx (1-\cos\theta) + y \sin\theta),\\
\qquad\ X(x y (1-\cos\theta) + z\sin\theta) +Y(y^2 (1-\cos\theta) +\cos\theta) + Z(yz (1-\cos\theta) – x \sin\theta),\\
\qquad\ X(z x (1-\cos\theta) – y\sin\theta) + Y(yz(1-\cos\theta) + x\sin\theta) + Z(z^2 (1-\cos\theta)+\cos\theta)\quad)
\end{array}$$Let us focus on the resulting imaginary vector (\(X’,Y’,Z’\)). This is nothing other than the result of applying the rotation matrix described on the previous page to (\(X,Y,Z\)):$$
\begin{pmatrix}X’\\Y’\\Z’\end{pmatrix}=
\begin{pmatrix}
x^2(1-\cos\theta) + \cos\theta & x y(1-\cos\theta) – z \sin\theta & z x (1-\cos\theta) + y \sin\theta\\
x y (1-\cos\theta) + z \sin\theta & y^2 (1-\cos\theta) + \cos\theta & y z (1-\cos\theta) – x \sin\theta\\
z x (1-\cos\theta) – y \sin\theta & y z (1-\cos\theta) + x \sin\theta & z^2 (1-\cos\theta) + \cos\theta
\end{pmatrix}
\begin{pmatrix}X\\Y\\Z\end{pmatrix}
$$In other words, the imaginary vector of \(B\) obtained by the transformation \(B=PAP^*\) is the imaginary vector of \(A\) rotated by \(\theta\) about the imaginary vector \((x,y,z)\) of \(P\).

 Note that when we regard a unit quaternion as a quantity representing a rotation state, \(P\) and \(-P\) cannot be distinguished. This is because “a rotation of angle \(\theta\) about the axis \((x,y,z)\)” is equivalent to “a rotation of angle \(-\theta\) about the axis \((-x,-y,-z)\)”:$$
PAP^*= (-P)A(-P)^*
$$

Angular Difference Between Two Unit Quaternions

 We hope you now understand that unit quaternions are quantities representing rotation states. So, given two unit quaternions, how do we find the angular difference between them (the minimum rotation angle connecting two rotation states, i.e., the misorientation)?

 First, let the two unit quaternions representing rotation states be \(P,Q\), and let \(A\) be an arbitrary quaternion with zero real part. When the imaginary vector of \(A\) is rotated by \(P\) and \(Q\), it maps to \(PAP^*\) and \(QAQ^*\), respectively. This is a recap of the previous section. Now suppose a unit quaternion \(R\) corresponds to the rotation \(P \rightarrow Q\). Then for all \(A\), the relation$$R(PAP^*)R^*=QAQ^*$$must hold, which means$$RP=Q\quad \rightarrow \quad R=QP^*$$If we only need the rotation angle \(\theta\) from \(P\) to \(Q\), we do not need all components of \(R\); it suffices to find the real part (\(\cos(\theta/2)\)). Defining$$P=(a_1,b_1,c_1,d_1), \qquad Q=(a_2,b_2,c_2,d_2)$$we get$$
\textrm{Re}(QP^*)=a_1a_2+b_1b_2+c_1c_2+d_1d_2=\cos(\frac{\theta}{2})\\\rightarrow \theta = 2\arccos(a_1a_2+b_1b_2+c_1c_2+d_1d_2)$$where \(\textrm{Re}\) denotes the function that extracts the real part of a quaternion. You may have noticed the similarity to the dot product formula for vectors. In real space, if we let two unit vectors be \(\vec{u}=(a_1, b_1, c_1,…)\) and \(\vec{v}=(a_2, b_2, c_2,…)\), and their angle be \(\theta\), then$$
\vec{u} \cdot \vec{v} = a_1a_2+ b_1b_2+ c_1c_2+… = \cos\theta
$$On the other hand, the quantity \( \textrm{Re}(QP^*)=a_1a_2+b_1b_2+c_1c_2+d_1d_2=\cos(\frac{\theta}{2})\) corresponds to the dot product when we regard \(P,Q\) not as quaternions but as 4-dimensional vectors. Despite the difference between \(\cos(\theta)\) and \(\cos(\theta/2)\), the remarkable similarity is quite inspiring. While I would like to explore this further, it is a topic beyond my expertise, so I will leave the detailed explanation to others6.

Distribution of Angular Differences

 Finally, let us use the properties of unit quaternions to consider the distribution of angular differences in random orientation states. Since mathematical formulas alone can be difficult to visualize, let us use an object with a specific shape as an example. Consider, for instance, the following astronaut. We assume this astronaut has an asymmetric shape (top-bottom, left-right), possessing no symmetry elements other than the identity transformation.

Consider a situation where a large number of such astronauts exist, all drifting in completely random orientations. If we pick any two astronauts and compute the angular difference in their orientations (ignoring translations), what would the probability distribution of the angular differences look like?

 The concept of unit quaternions is useful for such problems. First, since unit quaternions represent rotation states, every astronaut’s orientation corresponds to some unit quaternion. Also, if we think of unit quaternions as points on a unit sphere in 4-dimensional space (where each component of the quaternion is assigned to each dimension), then a random orientation (posture) state corresponds to a set of points uniformly distributed on the 4-dimensional unit sphere. Furthermore, instead of choosing two points arbitrarily, we can fix one and choose the other arbitrarily without loss of generality. Thus, this problem is equivalent to asking: “What is the probability of finding a point at angle \(\phi\) from a given point on the 4-dimensional sphere?” Note that the angle \(\phi\) between two points (vectors) on the 4-dimensional unit sphere and the angular difference of rotation states \(\theta\) are related by \(\phi=\theta/2\).

 Let us now derive the answer following this approach. First, choose a “north pole” point \(P\) on the 4-dimensional unit sphere. The set of points at angle \(\phi\) from the north pole \(P\) forms not a latitude circle but a latitude surface. This latitude surface is a 3-dimensional sphere7, and its radius is \(\sqrt{1-\cos^2\phi}=\sin\phi\), so its surface area is \(4\pi \sin^2\phi\). This means the misorientation distribution function \(F(\phi)\) is proportional to \(\sin^2\phi\). Also, since the south pole \(-P\) represents the same rotation state as the north pole \(P\), points on the southern hemisphere should be considered in terms of their angle from the south pole \(-P\). This means the range of \(\phi\) from \(0\) to \(\pi/2\) (northern hemisphere only) is sufficient. Finally, substituting \(\phi=\theta/2\) and normalizing, we obtain the following misorientation distribution function \(F(\theta)\):

$$F(\theta)=\frac{2}{\pi}\sin^2\frac{\theta}{2} =\frac{1-\cos\theta}{\pi}\\ \qquad \textrm{where}\ 0\le\theta\le\pi $$

The following figure shows the horizontal axis in degrees rather than radians. The tendency for the probability of finding a small angular difference (\(\theta\) is small) to be low, increasing for larger differences, and reaching a gentle maximum at 180 degrees, should be intuitively understandable.


  1. https://qiita.com/OmojiP/items/f1d3320483462907a796 provides a detailed explanation. ↩︎
  2. Writing it out straightforwardly:$$ \begin{array}{l}
    (a_1+b_1i+c_1j+d_1k)(a_2+b_2i+c_2j+d_2k) \\
    \quad =a_1a_2+a_1b_2i+a_1c_2j+a_1d_2k + b_1a_2i+b_1b_2i^2+b_1c_2ij+b_1d_2ik\\
    \qquad +c_1a_2j+c_1b_2ji+c_1c_2j^2+d_2jk + d_1a_2k+d_1b_2ki+d_1c_2kj+d_1d_2k^2\\
    \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 \\
    \qquad +(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}$$ ↩︎
  3. For three quaternions \(A,B,C\), associativity holds: \((A+B)+C=A+(B+C)\), \((AB)C=A(BC)\). ↩︎
  4. A quaternion with zero real part is called a pure imaginary quaternion. ↩︎
  5. Of course, my ability alone was insufficient, so I relied on AI. Through the double angle formula, the \(\theta/2\) terms cancel out and \(\theta\) emerges. ↩︎
  6. https://kt-project.com/wp/math/number-theory/quartanion/math4-3/ ↩︎
  7. In 3-dimensional space, latitude circles are 2-dimensional circles. Think of it as increasing one dimension from that. ↩︎

contents