A lot of people use quaternions to represent object orientations and to perform rotations in a dependable way, without actually understanding how they work. This is peculiar as the discovery of quaternions is often cited as perhaps the most documented discovery in the history of mathematics. Unfortunately, Hamilton gave the world a poor first impression because he had trouble understanding quaternions. A decade-long campaign of misinterpretation and confusion later, quaternions $\mathbb{H}$ were whisked away to the plane of oblivion for more than a century, at least as far the mainstream public was concerned. But not before its carcass was picked clean by the likes of Gibbs and Heaviside who independently brought about vector algebra and calculus in the modern sense, among other things.

This article aims to show how quaternions can be derived and why they manage rotations in such an efficient, reliable and elegant manner. It also sets the stage for follow up articles on geometric algebra which will more clearly illustrate the useful properties quaternions have (as they're a subalgebra of it). Not to mention open your eyes to see just how badly one man's confusion in 1843. gave mathematical physics a limp we're yet to get rid of.

A quick rundown of \(\mathbb{C}\)

Complex numbers are the algebraic basis for arriving at quaternions, as their properties motivate the development of quaternions. As you should already know, complex numbers arise when one desires to solve the canonical \(x^2 + 1 = 0\) by defining an indeterminate \(i\) as the solution. Complex numbers have a real and imaginary part, both of which are real numbers. The imaginary part enumerates the indeterminate and when combined with the real part, it forms an algebraic extension of real numbers and enables solutions of polynomials such as the one that motivated the extension. We can write a complex number as:

$$ z = x1 + yi $$

They may look a bit peculiar to people, but they're as "legit" as real numbers are. Here's a simple example, we will square the expression above and procure yet another complex number:

$$ z^2 = (x + yi)^2 = x^2 + 2xyi + y^2i^2 = x^2 - y^2 + 2xyi$$

Much like the set of real numbers \(\mathbb{R}\), \(\mathbb{C}\) is a field which, among other terms, predicates being closed under multiplication. Just like one can plot real numbers on the number line, complex numbers may be plotted in the complex plane which can be visualized as two real number lines setup perpendicular to one another. One plots the real part on the horizontal "axis" and the imaginary part on the vertical one.

The complex plane is not a complex vector space.

Some people erroneously conflate complex vector spaces and the complex plane. \(1\) and \(i\) are not to be thought of as linearly independent bases. As mentioned, the set of complex numbers is a field and can merrily replace real numbers as scalars of a vector space, in which case it becomes a complex vector space. Complex numbers themselves are not vectors. Complex numbers can be constructed as ordered pairs with special operations defined on them. But an ordered pair is not a vector. Historically, vector spaces came after quaternions which came after complex numbers.

Like real numbers, complex numbers define absolute value to coincide with the distance from the origin. Unlike real numbers, though, we have to avail ourselves of some geometric insights to compute the absolute value or modulus. Thus, the absolute value of \(z\) is equal to \(\sqrt{x^2 + y^2}\). While we're here, we may as well introduce the complex conjugate by showing how one can compute the absolute value with its help:

$$ \sqrt{x^2 + y^2} = \sqrt{x^2 - y^2i^2 + xyi - xyi} = \sqrt{(x + yi)(x - yi)} = \sqrt{zz^*} $$

In the complex plane, all complex numbers can be thought of as directed segments from the origin thanks to the associated absolute value / modulus. The behavior or basic addition and subtraction may be reminiscent of what you know of vector algebra, which should give you a clear historical perspective where that came from. However, complex numbers also have interesting geometric interpretations when it comes to multiplying and dividing them. To best illustrate this without actually needing to whip out graphs, we will transform to polar form and further compact it by using Euler's relation:

$$ z = r(\cos\theta + i\sin\theta) = re^{i\theta} $$

To transform to polar form, \(r\) is just the absolute value of \(z\), \(|z|\), the distance to the origin. You recover \(\theta\) with \(\tan^{-1}(y/(r+x))\), which is the angle to the horizontal "axis". Now, I want you to observe what happens when you multiply two complex numbers:

$$ z_1z_2 = r_1e^{i\alpha} r_2e^{i\beta} = r_1r_2e^{i(\alpha + \beta)} $$

Interestingly, the angles from the horizontal axis are being added together while the radii are multiplied together. As we already mentioned, the radius is the absolute value or modulus, the distance to the origin. The fact that the modulus of the product is equal to the product of the two moduli was called the law of the moduli by Hamilton and was one of the requirements when he was searching for quaternions. This rather trivial-looking law is of importance, as we can now talk of a complex number $R$ with $r=1$ which has the ability to rotate $z$ by an angle $\theta$:

$$ Rz = zR = e^{i\theta} re^{i\alpha} = re^{i(\alpha + \theta)} = z' $$

This was a profound insight, one sorely known to Hamilton. Keep in mind the commutativity of the complex product, as it is a notable feature courtesy of the commutativity of the addition of real numbers. This result may also encourage one to think about the division of two directed segments:

$$ \frac{z_1}{z_2} = \frac{r_1}{r_2}e^{i(\alpha - \beta)} $$

When two directed segments are parallel (the angle is $0$), the result is the positive ratio of their lengths (and thereby norms). When they're anti-parallel (angle of $\pi$), the exponential degenerates to $e^{i\pi} = \cos\pi + i\sin\pi = -1$ which intuitively signs the ratio of the lengths to be negative. The last option is that they have some general angle of separation, at which point division encodes both angular and length information. In case of unit directed segments, their division can be used to recover the angle between them. Hamilton desperately wanted to generalize this to the third dimension, but given that you have never heard of vector division in this sense in classic vector algebra, you may guess on his success. To be honest, the last two concepts discussed, rotating by a single product and the idea of the quotient of two directed segments, brought the entire ship down through a case of chronic underestimation and shortsightedness. The dogmatic perserverence that the same must hold in three dimensions instead of assuming that they're just special cases of a much more general construct. But more on that later.

Going from \(\mathbb{C}\) to \(\mathbb{H}\)

While the geometric interpretation was never far from Hamilton's mind, the way he arrived at quaternions was purely algebraic. Which incidentally may be one of the problems, because Hamilton and his followers tried to shoehorn the geometric interpretation of complex numbers after the fact without giving proper weight to the whole "adding a new dimension" thing. So, we retread the steps, as promised, but for brevity, we don't make all the wrong turns as part of our derivation.

Hamilton did the obvious expansion of complex theory, he added yet another imaginary part and indeterminate $j$ which squared to $-1$ and was presumed perpendicular to both the real and imaginary axis (when interpreting geometrically). Trouble catches up to us once we try to multiply two generic triplets in this new algebra we're crafting and attempt to see whether it is closed under multiplication like \(\mathbb{C}\) is, but you might guess where this is going:

$$\begin{split} q_1q_2 & = (x_1 + y_1i + z_1j)(x_2 + y_2i + z_2j) \\ & = x_1x_2 - y_1y_2 - z_1z_2 \\ & + (x_1y_2 + x_2y_1)i \\ & + (x_1z_2 + x_2z_1)j \\ & + (y_1z_2 - y_2z_1)ij \\ \end{split}$$

As expected, a higher grade term emerges and is not going away. To close the algebra, we make the safe assumption $ij = k$ and add $k$ into the mix, which Hamilton himself was dumbfounded by, describing it as a paradox:

$$\begin{split} q_1q_2 & = (x_1 + y_1i + z_1j + w_1k)(x_2 + y_2i + z_2j + w_2k) \\ & = x_1x_2 - y_1y_2 - z_1z_2 - w_1w_2 \\ & + (x_1y_2 + x_2y_1)i + (x_1z_2 + x_2z_1)j + (x_1w_2 + x_2w_1)k \\ & + (y_1z_2 - y_2z_1)ij + (y_1w_2 - y_2w_1)ik + (z_1w_2 - z_2w_1)jk \\ \end{split}$$

Given that we established $ij = -ji$, key being the anticommutative property, we assert $ik = -ki$ and $jk = -kj$ as well. We also hold that $i^2 = j^2 = k^2 = -1$ as we're trying to generalize complex numbers in some way. $ij = k$ imposes $ik = iij = -j$, $jk = -ikk = i$ and $ijk = kk = -1$:

$$\begin{split} q_1q_2 & = (x_1 + y_1i + z_1j + w_1k)(x_2 + y_2i + z_2j + w_2k) \\ & = x_1x_2 - y_1y_2 - z_1z_2 - w_1w_2 \\ & + (x_1y_2 + x_2y_1 + z_1w_2 - z_2w_1)i \\ & + (x_1z_2 + x_2z_1 + y_2w_1 - y_1w_2)j \\ & + (x_1w_2 + x_2w_1 + y_1z_2 - y_2z_1)k \\ \end{split}$$

All of this is a pretty big deal, as in the case of triplets there is nothing you can do to close the algebra or, in other words, make $ij$ go away. Once we uncover the exponential form in the next few sections, we will show that the law of moduli holds, along with some information on why it matters. Though, nothing is preventing you from bruteforcing it right now. In case you forgot what the law of moduli was, it's $|q_1||q_2| = |q_1q_2|$. Simple, but extremely potent.

Keeping up with the Hamiltons

Mankind divided over vectors divided

Hamilton knew what he wrapped his hands around the day it dawned on him to shift to the fourth dimension. Historical documents suggest he immediately started searching for the geometric interpretation of his discovery, getting basic rotations going by the end of the first day. There were three main notions from complex numbers that he wanted to generalize. The ability of complex numbers to represent directed segments, the ability of complex numbers to rotate those segments via a single complex product and the notion that one could recover useful information akin to the dot product through the concept of vector division. In fact, Hamilton was so obsessed with vector division that he actually defined the quaternion in terms of it: A quaternion is the quotient of two vectors, in the general case.

Hamilton introduced the terms vector and scalar

As you might know, in the first half of the 19th century, there was no formal notion of vectors. There were many informal approaches which were used to obtain useful results, concepts of directed segments and arrows can be observed in works from the 17th century, such as in the works of Sir Isaac Newton. But these constructs were not called vectors.

Hamilton based the term vector on the Latin verb vehere meaning "to carry". Similarly, he was the one who came up with the term scalar. The name vector was introduced to augment Hamilton's developing quaternion theory, where he considered the imaginary part to form a directed segment (now referred to as a vector), whereas the real part was considered the scalar. Furthermore, in Hamilton's quaternion algebra, a real number could be expressed as a real quaternion with a zero imaginary vector $\mathbf{0}$, $(a, \mathbf{0})$. Contrasting this is a pure quaternion which consists of a non-existent scalar part and the imaginary vector $(0, \mathbf{v})$.

That obviously isn't the case today, so what happened? A geometric interpretation. In common vernacular, everything is subject to interpretation and there are many views that humans accept as valid even though they're most certainly expressing a subset of the whole truth. Due to Hamilton's heavy bias towards the geometric interpretation of complex numbers and making strong, unsubstantiated assumptions about the behavior of quaternions, he was wrong on many levels. This is a bit disappointing as a physicist should know that many things which are true in two dimensions are outright false or false in the general case in three dimensions or more. One example is the relationship between vector quantities of angular momentum and angular velocity in modern physics. In two dimensions, they share direction. In three dimensions, they can be offset by a considerable angle giving rise to what is sometimes referred to as gyro motion.

Geometric interperation of \(\mathbb{H}\)

Back on track!

The crux of the problem here is that Hamilton failed to recognize the two-dimensional interpretation of complex numbers as the special case, not the norm. Initial surveying of the geometric interpretation of quaternions was done manually, by trying to map out where the result gets placed in three dimensional space (by treating the imaginary part as a directed segment or vector, as positions/directions versus rotations). We will do something a bit different. We recognize how obvious the geometric interpretation of complex numbers becomes in exponential form, so that might be a good start for us. There are multiple ways of arriving at an exponential form, by writing out the series or alternatively going back to Euler's relation with a few tricks up our sleeve. First, verify for yourself that the following statements are all true:

$$|q|^2 = |s|^2 + |\mathbf{v}|^2$$

$$q = s + \mathbf{v} = |q|\Bigg( \frac{|s|}{|q|} + \frac{|\mathbf{v}|}{|q|} \frac{\mathbf{v}}{|\mathbf{v}|} \Bigg)$$

$$ \begin{split} \mathbf{\hat{v}}^2 &= (v_xi + v_yj + v_zk)(v_xi + v_yj + v_zk) \\ &= \mathbf{\hat{v}} \times \mathbf{\hat{v}} - \mathbf{\hat{v}} \cdot \mathbf{\hat{v}} = \mathbf{0} - 1 = -1 \end{split} $$

Transform the modulus expression by dividing both sides by $|q|^2$:

$$1 = \Bigg( \frac{|s|}{|q|} \Bigg) ^2 + \Bigg( \frac{|\mathbf{v}|}{|q|} \Bigg) ^2 $$

Apply the trigonometric identity $\cos^2\theta + \sin^2\theta = 1$ by assuming there exists $\theta$ which satisfies:

$$ \frac{|s|}{|q|} = \cos\theta \qquad \frac{|\mathbf{v}|}{|q|} = \sin\theta $$

As \(\mathbf{\hat{v}}^2 = -1\), the Euler relation holds here as well:

$$q = s + \mathbf{v} = |q|( \cos\theta + \mathbf{\hat{v}} \sin\theta) = |q|e^{\mathbf{\hat{v}}\theta} $$

Satisfying the law of moduli

With the exponential form in hand, it becomes easy to show $|q_1||q_2| = |q_1q_2|$:

$$|q_1||q_2| = \sqrt{q_1q_1^*q_2q_2^*} = \sqrt{|q_1|^2|q_2|^2e^{\mathbf{\hat{v}}_1(\alpha - \alpha) + \mathbf{\hat{v}}_2(\beta - \beta)}} = \sqrt{q_1q_2(q_1q_2)^*} = |q_1q_2|$$

Only 4 normed division algebras satisfy this rule (and thus exist), $\mathbb{R}$, $\mathbb{C}$, $\mathbb{H}$ and an algebra that follows naturally from quaternions, octonions $\mathbb{O}$.

It is immediately visible that a compact exponential form will not trivially reveal how exactly we can achieve rotations through multiplication due to the added dimensionality. Thus we will not make use of Euler's relation here and just proceed in the expanded form. We will attempt, much like Hamilton, to multiply a quaternion representing the rotation \(r\) with a quaternion \(p\) representing the position we're interested in rotating. Hopefully, by expanding, we will determine which part of the rotation quaternion defines the plane of rotation and whether or not an actual proper rotation takes place.

$$rp = |p|( \cos\theta + \mathbf{\hat{r}}_v \sin\theta)( \cos\alpha + \mathbf{\hat{p}}_v \sin\alpha) $$

The position quaternion has no scalar component at all, which in this form needs to be eliminated by setting \(\alpha = \pi/2\). And then we just:

$$ \begin{split} rp &= |p|( \cos\theta + \mathbf{\hat{r}}_v \sin\theta)\mathbf{\hat{p}}_v \\ &= |p|( \mathbf{\hat{p}}_v\cos\theta + \mathbf{\hat{r}}_v\mathbf{\hat{p}}_v \sin\theta) \\ &= |p|( \mathbf{\hat{p}}_v\cos\theta + (\mathbf{\hat{r}}_v \times \mathbf{\hat{p}}_v - \mathbf{\hat{r}}_v \cdot \mathbf{\hat{p}}_v) \sin\theta) \end{split} $$

It follows that the only way to have a rotated pure quaternion result is iff \( \mathbf{\hat{r}}_v \cdot \mathbf{\hat{p}}_v = 0 \), which is to say that the point needs to be in the rotation plane. This is not very useful. Hamilton was very excited about this, though. He thought he had finally generalized the geometric interpretation of complex numbers to three dimensions with quaternions and some help from the "paradoxical" fourth dimension. This little escapade of ours hasn't been a total bust, though. We now know for sure that \(\mathbf{\hat{r}}_v = \mathbf{\hat{n}}\), it is the rotation plane's normal. Our next step is to explore this further. It is reasonable to expect arbitrary rotations are possible and that the result will be a pure quaternion with its norm preserved. To this end, we must find a way to extrapolate the scalar part from a quaternion. Since we don't have much to go on, removing the scalar part is a good start. This is fairly easy if you remember your conjugation:

$$q + q^* = 2w = 2S(q) \iff S(q) = \frac{q + q^*}{2}$$

Seems rather trivial, but it's useful nonetheless, as we can posit requirements such as that whatever the missing piece of our product, we desire $S(\hat{r}p\hat{q}) = 0$. We also know that proper rotations preserve norm, so $|\hat{r}p\hat{q}| = |p|$. We can constrain $\hat{q}$ by:

$$ S(\hat{r}p) = S(p\hat{q}) \iff S(\hat{r}p\hat{q}) = S(\hat{r}p) - S(p\hat{q}) = 0 \iff \hat{q} = \hat{r}^*$$

Conjugates negate the imaginary vector part leaving the scalar part untouched. That's how we formulated the scalar extraction function in the first place. Finally, let's check the norm requirement knowing that we're working with unit quaternions and that $|q| = |q^*|$:

$$|\hat{r}p\hat{r}^*| = |\hat{r}||p||\hat{r}^*| = |p|$$

This allows us to propose the following transform:

$$ \Large { p' = \hat{r}p\hat{r}^* = \hat{r}p\hat{r}^{-1} }$$

Right off the bat, one can guess there's a double transform by \(\theta\) going on here. However, to get the details, we have to work it out:

$$ \begin{split} \mathbf{p'} = \hat{r}p\hat{r}^* &= |p|[\cos\theta + \mathbf{\hat{n}}\sin\theta]\mathbf{\hat{p}_v}[\cos\theta - \mathbf{\hat{n}}\sin\theta] \\ &= |p|[ \mathbf{\hat{p}_v}\cos\theta + \mathbf{\hat{n}}\mathbf{\hat{p}_v} \sin\theta] [\cos\theta - \mathbf{\hat{n}}\sin\theta] \\ &= |p|[ \mathbf{\hat{p}_v}\cos^2\theta + (\mathbf{\hat{n}}\mathbf{\hat{p}_v} - \mathbf{\hat{p}_v}\mathbf{\hat{n}})\sin\theta\cos\theta - \mathbf{\hat{n}}\mathbf{\hat{p}_v}\mathbf{\hat{n}} \sin^2\theta] \\ &= |p|[ \mathbf{\hat{p}_v}\cos^2\theta + (\mathbf{\hat{n}} \times \mathbf{\hat{p}_v} - \mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v} + \mathbf{\hat{n}} \times \mathbf{\hat{p}_v} + \mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\sin\theta\cos\theta - (\mathbf{\hat{n}} \times \mathbf{\hat{p}_v} - \mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}} \sin^2\theta] \\ &= |p|[ \mathbf{\hat{p}_v}\cos^2\theta + 2\mathbf{\hat{n}} \times \mathbf{\hat{p}_v}\sin\theta\cos\theta - (\mathbf{\hat{n}} \times \mathbf{\hat{p}_v} \times \mathbf{\hat{n}} - (\mathbf{\hat{n}} \times \mathbf{\hat{p}_v}) \cdot \mathbf{\hat{n}} - (\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}})\sin^2\theta] \\ &= |p|[ \mathbf{\hat{p}_v}\cos^2\theta + 2\mathbf{\hat{n}} \times \mathbf{\hat{p}_v}\sin\theta\cos\theta - (\mathbf{\hat{p}_v} (\mathbf{\hat{n}} \cdot \mathbf{\hat{n}}) - 2(\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}})\sin^2\theta] \\ &= |p|[ \mathbf{\hat{p}_v}(\cos^2\theta - \sin^2\theta) + 2\mathbf{\hat{n}} \times \mathbf{\hat{p}_v}\sin\theta\cos\theta + 2(\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}}\sin^2\theta] \\ \end{split}$$

At this stage, we can confirm that the scalar part has been completely eliminated, but we still need to simplify the expression to understand the semantics of quaternion rotation. The following trigonometric identities should help us do so, which you may already know:

$$ \cos(2\theta) = \cos^2\theta - \sin^2\theta \qquad \sin(2\theta) = 2\sin\theta\cos\theta \qquad \sin^2(\theta) = \frac{1 - \cos(2\theta)}{2} $$

And we can finally unravel the product:

$$ \begin{split} \mathbf{p'} = \hat{r}p\hat{r}^* &= |p|[\cos\theta + \mathbf{\hat{n}}\sin\theta]\mathbf{\hat{p}_v}[\cos\theta - \mathbf{\hat{n}}\sin\theta] \\ &= |p|[ \mathbf{\hat{p}_v}(\cos^2\theta - \sin^2\theta) + 2\mathbf{\hat{n}} \times \mathbf{\hat{p}_v}\sin\theta\cos\theta + 2(\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}}\sin^2\theta] \\ &= |p|[ (\mathbf{\hat{p}_v} - (\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}})\cos(2\theta) + \mathbf{\hat{n}} \times \mathbf{\hat{p}_v}\sin(2\theta) + (\mathbf{\hat{n}} \cdot \mathbf{\hat{p}_v})\mathbf{\hat{n}}] \\ &= (\mathbf{p_v} - (\mathbf{\hat{n}} \cdot \mathbf{p_v})\mathbf{\hat{n}})\cos(2\theta) + \mathbf{\hat{n}} \times \mathbf{p_v}\sin(2\theta) + (\mathbf{\hat{n}} \cdot \mathbf{p_v})\mathbf{\hat{n}} \end{split}$$

If you're having trouble seeing what's going, maybe the following substitutions can help:

$$ \mathbf{p'} = \hat{r}p\hat{r}^* = (\mathbf{p_v} - \mathbf{p_{\parallel}})\cos(2\theta) + \mathbf{p_{\perp}}\sin(2\theta) + \mathbf{p_{\parallel}} $$

Disregarding the factor doubling the angle, this is the exact same conical transformation you arrive at geometrically in linear algebra. In fact, this was its first appearance. Double angle is easily mitigated by supplying the rotation quaternion with half the intended angle. The beauty of quaternions is that they're extremely compact and implicit with respect to other representations, they're tolerant of precision loss and you can trivially recover the plane of rotation and the angle involved. But most of all, quaternion rotation doesn't suffer from what people annoyingly keep referring as the gimbal lock. We're talking about potential singularities caused by mapping deficiencies of the chosen representation.

Relationship with rotation group $SO(3)$

I will attempt to keep this as simple as possible, which will most definitely come at the expense of accuracy. I recognize that a lot of people don't have a background in abstract algebra and topology, and quite frankly, they don't even want one. In the future, I might make a series taking a deeper dive into this, but for now, let's just show what makes quaternions so well suited for representing rotations.

The three-dimensional rotation group $SO(3)$ is the group of all rotations around the origin of \(\mathbb{R}^3\) under composition. In other words, composing rotations will result in yet another rotation. The order in which you compose rotations matters, hence the group is non-abelian. The group of all rotations under composition sounds very abstract, because it is. It doesn't really describe how you can make a rotation, that's the job of a representation which conceptually maps to the group of all rotations with varying degrees of success. Representations always come first in terms of "discovery". The most common representation this rotation group is identified with are \(3\times3\) orthonormal rotation matrices which form a group under matrix multiplication and encode rotations with a discernible rotation axis and angle. But the one that helped formalize the various properties of the group was actually the discovery of the quaternion group.

To illustrate this in a lower dimension, we discussed the geometric interpretation of the multiplication of complex numbers at the start of this article and how complex numbers of absolute value \(1\) can represent rotations, encoding the angle as shown in the compact polar form \(e^{i\theta} = \cos\theta + i\sin\theta\). Strictly speaking, complex numbers of absolute value $1$ form a group under multiplication called \(\mathbf{U}(1)\). Clearly the set of all such complex numbers forms a unit circle in the complex plane, which we tag as \(S^1\). Hence, it stands to reason it can have an isomorphism (an invertible mapping) to the group of all \(2\times2\) orthonormal rotation matrices which can be identified with \(SO(2)\):

$$ \Large { e^{i\theta} \Rightarrow \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix} } $$

Thus, we prove the isomorphism. For three dimensions, things are not so simple. As you saw when we derived the geometric interpretation of the group of unit quaternions under multiplication. The rotation axis is no longer implicit. Quaternions, and the time you surely spent constructing \(3\times3\) orthonormal rotation matrices, showed us that we need both a rotation axis and an angle. And speaking of unit quaternions, what kind of topology are we dealing with? Well, if you take a look at how their norm is computed, all the unit quaternions define a sphere in four dimensional space, a 3-sphere $S^3$ which happens to be three dimensional. This is to facilitate both encoding the rotation axis and angle as we derived in previous sections.

Following are some observations about rotations by an angle around an axis. A rotation around axis \(\mathbf{n}\) with angle \(\theta\) is the same rotation as the one around \(-\mathbf{n}\) with angle \(-\theta\). The two rotation axes lie on the same line. Additionally, when the rotation angle is \(\pi\), the sign of the axis doesn't change the result, it's the same rotation. Thus, since the set of all unit quaternions is encoding all possible axes and angles, this also means it has redundant elements which map to the same rotation. We'll get back to this in a jiffy.

For the following remark, imagine the \(2\)-sphere to more easily understand what's going on. If you have a line going through a sphere, it will intersect it in two places. This much is clear. When this line goes through the center of the sphere, the two intersections are said to be antipodal to each other. This is useful information because of what we've already discussed, namely \(R(\mathbf{n}, \theta) = R(\mathbf{-n}, -\theta)\). Given the 3-sphere formed by unit quaternions, these mutually redundant points are on opposite ends, they're antipodal points and need to be taken care of if we're going to show that the group of quaternions can be mapped to the group of all rotations. This is done with a simple mapping of one point to the other, which in topological freestyle lingo is called "gluing" them together. This leaves us in the topological space of the group of all rotations, which happens to be the real projective space, \(\mathbb{RP}^3\).

In case you're not familiar, the real projective space is, really, the mathematical take on something you might be very familiar with — perspective. Chronologically, the study of real projective spaces was inspired by painters, after they figured out how to paint their surroundings in a way that doesn't look like a doodle of a Bohemian peasant from 1403. In other words, when they figured out perspective. It comes down to having the set of all lines that pass through the origin in \(\mathbb{R}^n\) be points in \(\mathbb{RP}^{n-1}\). For example, when you have a 3-sphere in \(\mathbb{R}^4\) centered on the origin (much like the one we've been describing), in \(\mathbb{RP}^3\) antipodal points are the same one, as they sit on the line passing through the origin. In fact, this is one way to define a real projective space. By identifying antipodal points on a 3-sphere. And in turn, we can surmise that the group of all rotations \(SO(3)\) is diffeomorphic to \(\mathbb{RP}^3\), a fact not obvious without the quaternion group. Diffeomorphism is an isomorphism between smooth manifolds. In simple terms, it's a well-behaved reversible mapping between the topological space of the group of all 3D rotations to the real projective space.

We can now conclude there is a 2:1 mapping between the quaternion and rotation group because \( \hat{q}p\hat{q}^* = (-\hat{q})p(-\hat{q}^*) \) (remember the antipodal points), making the quaternion group a double cover of \(SO(3)\). More specifically, a surjective homomorphism. This means any change in the target space can be replicated in the source space. Which for you means no more annoyed users who had their spaceship camera controls freak out because they disagreed with your definition of which way is up.