Quaternions: Rotations Without Gimbal Lock
Select any 3D object in Unity, Unreal or Godot and the inspector shows you friendly angles. Look at what the engine actually stores, though, and you find four odd-looking numbers instead: a quaternion. It is the engine's answer to both Euler-angle traps.
The rule
Halve the angle: w is its cosine, and its sine scales the axis.
Any orientation can be reached with a single turn by some angle about some axis. A unit quaternion stores that one turn as four numbers :
where is the axis as a unit vector. The four numbers always satisfy .
- No turn at all is .
- 90° about the vertical axis : the half-angle is 45°, so .
- 180° about the same axis: the half-angle is 90°, so .
Why engines like them:
- Combining two turns is a single quaternion multiplication; as with matrices, the order matters.
- Undoing a turn is cheap: flip the signs of x, y and z.
- Slerp (spherical linear interpolation) blends two orientations along the shortest arc at a steady speed, which is ideal for a chase camera easing round behind the drone.
- No gimbal lock: there are no three separate axes that can line up.
One oddity: and describe the same orientation. Turning a full 360° gives , yet the drone is back exactly where it started. Slerp checks for this so it always takes the short way.
The shortcut
To write a quaternion by hand: make the axis unit length, halve the angle, set w = cos(half) and (x, y, z) = sin(half) × axis. Then check that the four squares add up to 1.
Axis
(0, 1, 0), already unit length.
The trap is forgetting to halve. Writing produces a perfectly valid quaternion for the wrong turn: twice the angle you meant. And never edit the four numbers by hand as if they were angles; change orientations through the engine's rotation functions.
Drills
Answer fast — trust the rule.
Which quaternion (w, x, y, z) means "no rotation"?
Which quaternion turns 180° about the vertical axis (0, 1, 0)?
For a turn of 60° about the vertical axis, what is w?
Why do engines store rotations as quaternions rather than Euler angles?
q and −q are both unit quaternions. What do they describe?
Remember
- A unit quaternion for a turn θ about unit axis a is w = cos(θ/2) and (x, y, z) = sin(θ/2) × a.
- Combine by multiplying (order matters), blend with slerp, and never hit gimbal lock.
- Traps: forgetting to halve the angle; q and −q are the same orientation.
