Quaternions· Visually
Home / Part A / 2

Any orientation is one turn about one axis

Lesson 2 · Interactive

Here is a surprising fact. However we tilted and turned the object, we can get to the same result with one single turn about one well-chosen axis. Quaternions are built on this idea, so we see it first.

2.1One axis, one angle

Pick a line through the object. That’s the axis. Turn the object about it by some angle θ. That’s it. Leonhard Euler proved that every orientation can be reached this way. It’s called Euler’s rotation theorem.

Visual 1 of 3 · One axis, one angle
Try it: choose an axis, then press Turn 0 → 360°. The outline is where the object started. The dashed purple path is the tip of the object. Every point of the object moves on a circle around the purple axis.

The direction of the turn follows the right-hand rule. Point your right thumb along the axis, and your fingers curl in the positive direction. Remember that x points forward, y to the left and z up. So a positive turn about z moves the arrow on the object from x toward y: to the left, counter-clockwise seen from above. A positive turn about y moves the front of the object down.

2.2How to write it down

We need two things: which way the axis points, and how much we turn.

The axis is a direction. We write a direction as an arrow of length 1, called a unit vector, \(\mathbf n = (n_x, n_y, n_z)\). The three numbers say how much the arrow points along x, along y and along z:

(1, 0, 0)the x axis
(0, 0, 1)the z axis, straight up
(0.6, 0, 0.8)tilted between x and z. Check the length: 0.6² + 0.8² = 0.36 + 0.64 = 1

Why length 1? Because the arrow should only say which way. (0, 0, 1) and (0, 0, 5) point the same way, so we agree to always use the one with length 1.

The angle θ says how much we turn about that arrow.

Visual 2 of 3 · A direction as three numbers
Try it: aim the purple arrow n with the two sliders. Its tip always stays on the ball of radius 1. The three coloured pieces are its three numbers.
\[\text{a rotation} = \text{axis } \mathbf n \text{ and angle } \theta, \qquad n_x^2+n_y^2+n_z^2 = 1\]

Look at the lab again. It has three sliders: two to aim the axis (around and up/down, like longitude and latitude on a globe) and one for the angle. Three sliders, the same count as roll, pitch and yaw. Both are ways to describe the same thing, an orientation in 3D, and that always takes three numbers.

2.3So why not just store the axis and the angle?

Good question. It’s simple and it has no gimbal lock. But two things go wrong when we compute with it.

Problem 1: "no turn" has no axis. A turn of 0° about x and a turn of 0° about z are exactly the same: nothing happens. So when the turn is very small, the axis is almost undefined, and a tiny error can flip it to a completely different direction. Numbers that jump like this are bad for code.

Problem 2: two turns don’t add. Turn 90° about x, then 90° about the world’s z axis (the world axes do not move). The result is again one turn about one axis. Which one? It’s 120° about the diagonal (0.58, 0.58, 0.58). The axes did not add, and the angles did not add either: 90 + 90 is not 120. There is a formula that gets this from the two axes and angles, but it is long and full of sines and cosines.

Visual 3 of 3 · Two turns are one turn
Try it: play the two turns, then play the single turn. Both end in the purple outline. Could you have guessed the axis of the single turn?
The idea

A quaternion stores the same axis and angle, just packed differently: with the sine and cosine of half the angle. With this packing, "no turn" is the clean number [1, 0, 0, 0], and combining two turns is one multiplication. We check the 120° example by hand in lesson 5. To see why the packing works, we first look at a 2D trick in the next lesson.

✓Check yourself

Is (0, 0.6, 0.8) a valid axis? And (1, 1, 0)?

The first one is: 0.36 + 0.64 = 1. The second has length √2, so we divide by √2 and use (0.71, 0.71, 0).

The object turns +90° about z (up). Its arrow pointed along x. Where does it point now?

Along y. A positive turn about z goes from x toward y, counter-clockwise seen from above.

+Sources and further reading

Next: Warm-up: multiplying complex numbers is rotating in 2D.