Quaternions are a four-dimensional number system of the form

where the basis is . It can also be seen as the sum of a scalar component and vector .

This structure is an an extension of complex numbers, and we define conjugate and magnitude similarly:

We also define the inverse , which follows the formula

Quaternion algebra has component-wise addition and scalar multiplication, and like complex numbers, has the following rule for multiplying bases:

3D Rotations

Quaternions are most commonly used in ๐Ÿ‘๏ธ Computer Vision or ๐Ÿฆพ Robotics to compute 3D rotations. This is analogous to how multiplying by a complex number with unit magnitude rotates points in the complex plane.

Visualizing Quaternion Rotation

Since a quaternion lies in 4D space, we canโ€™t visualize its effect directly. However, we can see the unit quaternion in 3D via stereographic projection where the projection of is the intersection of a line through and with the imaginary hyperplane.

The function is a multiplication of a rotation quaternion with a unit quaternion . Each of the points is a key-point on the 4D unit hypersphere, and the two perpendicular circles are two chosen spheres on the hypersphere; note that the yellow line is still a circle, but one of its points is at infinity. Below is another visualization that transforms the yellow sphere so it can be projected as a circle instead of a line.

In this visualization, multiplying with a rotation rotates these two circles. For examples, if we let

moves to in the yellow circle, and moves to in the red circle, both completing 90-degree rotations. More generally, for multiplication with any quaternion that uses all four bases

our projected sphere both rotates and expands into a plane as our real component decreases.

More visualizations and further explanations can be found here thanks to Ben Eater and 3B1B.

Application in Engineering

To use quaternions for rotations, we usually want to isolate rotations and avoid the synced double-rotations observed above. Let

For the simple case where and , we observe that if we visualize and , the circle defined by and rotates in opposite directions while the other circle defined by and rotates in the same direction. Combining them together and noting that (since is unit), we arrive at the general rotation formula

These multiplications result in the former circleโ€™s rotation cancelling out and the latter circleโ€™s rotation compounding; visually, the first multiplication โ€œbubblesโ€ the projected sphere outwards and the second multiplication โ€œshrinksโ€ it back, but both are rotating the sphereโ€™s equator perpendicular to the axis.

This property holds for any unit axis of rotation . Our function thus gives a general method for rotating around axes in 3D by negating the rotation in the extra fourth (real) dimension, and it can be implemented as simple quaternion multiplication following the rules above.