The idea: four numbers for one turn
Every rotation of 3D space about the origin is a turn by some angle θ about some axis u (a unit vector). A unit quaternion packs that axis and angle into four numbers:
q = cos(θ/2) + sin(θ/2)(ux i + uy j + uz k)
The first number w = cos(θ/2) is the real part; the other three are the axis, scaled by sin(θ/2). Note the half angle: a 90° turn uses cos 45° and sin 45°. Since cos² + sin² = 1 and |u| = 1, the four numbers always satisfy w² + x² + y² + z² = 1. (Demo 1: axis and angle → q)
i, j, k: complex numbers one level up
A quaternion is w + x i + y j + z k with three imaginary units and Hamilton's rule
i2 = j2 = k2 = ijk = −1.
From it: ij = k, jk = i, ki = j, but ji = −k, kj = −i, ik = −j. The product is not commutative. The complex numbers are the case with only i: there a unit number cos θ + i sin θ turns the plane by θ, and here a unit quaternion turns space. The conjugate q* = w − x i − y j − z k undoes a unit quaternion: q q* = |q|2 = 1.
Turning a point: v' = q v q*
Write the point as a pure quaternion (real part 0): T = (0, 1, 1) becomes v = j + k. Then multiply on both sides:
v' = q v q*
For 90° about z, q = √2/2 + √2/2 k. First q v = √2/2(−1 − i + j + k), then (q v) q* = −i + k, so T moves to (−1, 0, 1). The real part always comes out 0, and the length stays √2. Each of the two factors turns by θ/2, which is why the half angle appears. The same turn as a 3 × 3 matrix has columns R·î, R·ĵ, R·k̂ (the facts panel); see 3D Rotation Matrices.
| turn | θ/2 | q |
|---|---|---|
| 0° | 0° | 1 |
| 90° about z | 45° | √2/2 + √2/2 k |
| 180° about x | 90° | i |
| 120° about (1, 1, 1) | 60° | ½ + ½i + ½j + ½k |
| 360° about any axis | 180° | −1 |
The 120° turn about the diagonal (1, 1, 1) cycles the axes: î → ĵ → k̂ → î. (Demo 2: 120° about (1,1,1): î → ĵ → k̂)
Composing: multiply, and the order matters
Turn by q1, then by q2: v → q2 (q1 v q1*) q2* = (q2 q1) v (q2 q1)*. So the combined turn is the product q2 q1, the later turn on the left, exactly like matrices R(q2) R(q1). Four numbers instead of nine, and 16 multiplications to combine two turns.
90° about x then 90° about y gives qy qx = ½ + ½i + ½j − ½k; the other order gives qx qy = ½ + ½i + ½j + ½k. Different quaternions, different orientations: 3D turns do not commute, and neither do quaternions. (Demo 4: multiply to compose (order matters))
q and −q: the same turn
In v' = q v q* a sign on q appears twice and cancels, so q and −q give the same rotation. Turning θ + 360° changes θ/2 by 180° and flips the sign of q. Turn the F once round, 360°: it is back where it started, but q = cos 180° = −1. Only after 720° is q = 1 again. Every rotation has exactly two quaternions: the unit quaternions double cover the rotations. (Demo 3: half angles: 360° gives −1)
This is not just algebra. Hold a plate flat on your palm and turn it one full turn under your arm: your arm is twisted. Keep going for a second full turn (over your head) and the arm comes back untwisted. The same holds for a belt with one end fixed (the belt trick or plate trick).
Euler angles and gimbal lock
Euler angles describe an orientation by three turns in a fixed order. Here, as in aircraft: yaw ψ about z, then pitch θ about the turned y, then roll φ about the F's own x: R = Rz(ψ) Ry(θ) Rx(φ). Picture them as three nested gimbal rings.
At pitch 90° the roll axis is turned onto the yaw axis. Then Ry(90°) Rx(φ) = Rz(−φ) Ry(90°), so R = Rz(ψ − φ) Ry(90°): yaw and roll spin the F about the same vertical line, only ψ − φ matters, and one of the three freedoms is gone. That is gimbal lock. Close to it, a small turn of the object needs huge changes of the angles. Quaternions have no such point: every orientation is a regular point on the unit sphere of four numbers. (Demo 5: gimbal lock at pitch 90°)
Slerp: smooth turns between orientations
To animate from orientation q0 to q1, slerp (spherical linear interpolation) moves along the great arc of the unit sphere between them:
slerp(q0, q1; t) = [sin((1 − t)Ω) q0 + sin(tΩ) q1] / sin Ω, cos Ω = q0 · q1.
The result is a turn about one fixed axis at a steady speed, the shortest way (use −q1 if q0 · q1 < 0). From the start to yaw 180°, pitch 60°, roll 180° (which is just 120° about y, q1 = ½ + √3/2 j), slerp turns 120°. Interpolating the three angles instead, (180t, 60t, 180t), reaches the same end but turns about 188° on the way, with a wobble you can see in the tip's path. (Demo 6: slerp vs Euler interpolation)
Facts at a glance
| property | quaternion q | matrix R |
|---|---|---|
| numbers stored | 4 (w² + x² + y² + z² = 1) | 9 (orthonormal columns) |
| axis and angle | read off: w = cos(θ/2), (x, y, z) = sin(θ/2) u | needs the eigenvector for λ = 1 |
| turn a point | q v q* | R v |
| first q1, then q2 | q2 q1 | R2 R1 |
| inverse | q* (flip the signs of i, j, k) | RT |
| same rotation | q and −q | one R |
| interpolation | slerp, smooth | awkward (re-orthonormalize) |
See also 3D Rotation Matrices, Complex Numbers (the 2D version: multiply by cos θ + i sin θ), Rotate and Scale in 3D, Rotation Matrix (2D), Composing Transforms, Changing Coordinates in 3D and Linear Transformations.
What the page leaves out
Non-unit quaternions (they also scale), quaternion division and the exponential form e(θ/2)u. Converting a matrix back to a quaternion (Shepperd's method), the other eleven Euler-angle orders and intrinsic vs extrinsic conventions, and the cheaper normalized lerp (nlerp) and squad for splines. Dual quaternions for turns plus translations, the group SU(2) and spinors behind the double cover, and floating-point drift (a unit quaternion is renormalized from time to time).