Quaternions are easier to understand as 5-dimensional

For a computer graphics developer, the 4-dimensional quaternion seems complicated, but by re-representing it as a 5-dimensional quantity, they can be easier to design with.

The idea doesn’t mean that quaternion algebra is altered, but a representation with 5 coordinates is simpler. It makes designing rotations easier to calculate.

A canonical quaternion is \(w+x\mathbf{i}+y\mathbf{j}+z\mathbf{k}\). or, as a vector \((w, x, y, z)\). The 5-dimensional representation is a vector \((m, \theta, a, b, c)\).

$$\sqrt{m}\left(\cos\frac{\theta}{2}+\sin{\frac{\theta}{2}}\left(a\mathbf{i}+b\mathbf{j}+c\mathbf{k}\right)\right) \text{ where } \|(a, b, c)\| = 1$$

Conjugating by this value corresponds to a rotation by \(\theta\) around the axis \((a, b, c)\) and scaling by a factor of \(m\). Although this is messier, it offers a much simpler conceptual framework.

The reason that this isn’t actually changing the dimensionality of a quaternion is because once you choose \(a\) and \(b\), then \(c\) only has two possible values. This drops the dimensionality back to its natural 4 again. The \(m\) usually drops out as well because if it is \(1\), there is no scaling in the rotation, the most common situation in computer graphics.

I’m loathe to use subscripts of \(\ _x\), \(\ _y\) and \(\ _z\) on the variables because they make the algebra indecipherable. I also would emphasize that understanding the meaning of the multiplication of two quaternions is irrelevant for computer graphics.

When rotating, one should only look at the rotation specification (conjugation by the quaternion), the point being rotated and the rotated point that is the result of the conjugation. I suggest not being intimidated trying to visualize 4-dimensional quaternion multiplication because the intermediate 4-tuples can be hidden behind a “rotate()” function and considered out-of-sight, out-of-mind.

It’s like organic chemistry. The result depends on the inputs and the process being applied. Once the process has been designed, the technician making the product does not need to know the details of the intermediate chemicals. Knowing basic safety rules can be enough.

In this form, if you want to rotate a graphic by an angle \(\theta\) around the vector \((p, q, r)\), you can start with the 5-parameter version describe above. Then you can multiply it out to get a normal quaternion:

$$\sqrt{m}cos\frac{\theta}{2} + a \left(\sqrt{m}\sin\frac{\theta}{2}\right)\mathbf{i} + b \left(\sqrt{m}\sin\frac{\theta}{2}\right)\mathbf{j}+c \left(\sqrt{m}\sin\frac{\theta}{2}\right)\mathbf{k}$$

You can then conjugate points by this constructed quaternion to rotate around an axis by the desired angle. The \(\sqrt{\ }\) is used because after the algebra calculating the rotation, it will result in a scaling by \(m\). \(\frac{\theta}{2}\) is used because the final rotation covers twice the angle used as the argument to the sine and cosine functions.

Since the value of \(m\) is going to be \(1\), you’re really finding 4 parameters. Now those 4 are a lot more meaningful than picking the values for a conventional quaternion without this extra step. The safety rule is that the rotation vector must be normalized to be a unit vector where \(\left(a^2+b^2+c^2\right) = 1\)

The derivation showing that any quaternion can fit into this representation starts with an arbitrary quaternion.

$$w+x\mathbf{i}+y\mathbf{j}+z\mathbf{k}$$

First, normalize the vector part so that it is becomes a unit vector by factoring out the magnitude of the vector.

$$w+\left(\sqrt{{x^2+y^2+z^2}}\right)\left(\frac{x}{\sqrt{x^2+y^2+z^2}}\mathbf{i}+\frac{y}{\sqrt{x^2+y^2+z^2}}\mathbf{j}+\frac{z}{\sqrt{x^2+y^2+z^2}}\mathbf{k}\right)$$

Note that the coefficients of the \(\mathbf{i}\), \(\mathbf{j}\) and \(\mathbf{k}\) form a unit vector, so I will write them as the desired \((a, b, c)\), simplifying the algebra a lot.

You can see that they are unit magnitude by squaring each segment and adding them:

$$\frac{x^2}{x^2+y^2+z^2}+\frac{y^2}{x^2+y^2+z^2}+\frac{z^2}{x^2+y^2+z^2}=\left(\frac{x^2+y^2+z^2}{x^2+y^2+z^2}\right)=1$$

Next, I simplify by factoring out the magnitude of the quaternion:

$$\left(\sqrt{w^2+x^2+y^2+z^2}\right)\left(\frac{w}{\sqrt{w^2+x^2+y^2+z^2}}+\frac{\sqrt{x^2+y^2+z^2}}{\sqrt{w^2+x^2+y^2+z^2}}\left(a\mathbf{i}+b\mathbf{j}+c\mathbf{k}\right)\right)$$

The next thing to observe is that the square of the coefficients of the vector and the scalar term, sum to \(1\) so that they are equivalent to the sine and cosine of some angle because of the identity \(\left(\sin{\phi}\right)^2+\left(\cos{\phi}\right)^2=1\). If two real number’s squares add to \(1\), there is some angle that fulfills the identity. Showing this uses the following derivation.

$$\left(\frac{w^2}{w^2+x^2+y^2+z^2}\right)+\left(\frac{x^2+y^2+z^2}{w^2+x^2+y^2+z^2}\right)=\left(\frac{w^2+x^2+y^2+z^2}{w^2+x^2+y^2+z^2}\right)=1$$

In summary, by representing a rotation as a 5-tuple, it’s easier to understand what is happening when you are doing rotations. Especially, since one of the parameters will normally be one, the four remaining parts of the quaternion have specific purposes that can be easily understood. For the purpose of rotation, quaternions are actually pretty simple.


Footnote: You can find warnings that one needs to be careful when the quaternion becomes “degenerate” because the vector part of the number is zero. This isn’t a problem with this description of applying quaternion rotations.

Normally, when you’re doing a rotation, you have an axis in mind for the rotation. This means that the vector part of the computed quaternion only becomes zero when \(\sin\frac{\theta}{2}\) is zero. That corresponds a rotation of zero. In such cases the vector part doesn’t matter, so a degenerate rotation just becomes a rotation around the same axis, but with \(\theta=0\)

Rather than turning a rotation by 0 into a special case, quaternions continue to eliminate special cases. Representing them as a 5-tuple makes the safety rules much easier to remember.