Unit Quaternions as Rotations

A quaternion is four numbers, q = w + xi + yj + zk, with the multiplication rules i^2 = j^2 = k^2 = ijk = -1. That algebra is pretty, but here is the payoff that makes every game engine and flight computer care: a unit quaternion is a 3-D rotation. One tidy product spins a vector through space — no gimbal lock, no drifting matrix, four numbers instead of nine. This page is the headline result of the whole branch, so we derive it line by line.

It is the three-dimensional sequel to a story you already know: on the plane, multiplying by a unit-modulus \cos\theta + i\sin\theta rotates. In 3-D we need three imaginary units instead of one — and, as we'll see, a curious half-angle.

The recipe, derived

We want to rotate a vector \mathbf{v} \in \mathbb{R}^3 by an angle \theta about a unit axis \hat{a} — exactly the job Rodrigues' formula does. The quaternion does it in three moves.

Step 1 — encode the vector as a pure quaternion. Glue the vector into the imaginary part of a quaternion with zero real part:

p = (0,\ \mathbf{v}) = 0 + v_x i + v_y j + v_z k.

A quaternion with no real part is called pure; pure quaternions are just a copy of \mathbb{R}^3 wearing a quaternion costume. Whatever we do to p, we'll read the rotated vector back out of its imaginary part.

Step 2 — build the unit rotation quaternion (the half-angle appears). Encode the axis and angle as

q = \left(\cos\tfrac{\theta}{2},\ \sin\tfrac{\theta}{2}\,\hat{a}\right) = \cos\tfrac{\theta}{2} + \sin\tfrac{\theta}{2}\,(a_x i + a_y j + a_z k).

Note the half-angle \theta/2 — not \theta. It is not a typo; Step 4 explains why it has to be there. Because \hat{a} is a unit vector, |q|^2 = \cos^2\tfrac{\theta}{2} + \sin^2\tfrac{\theta}{2}\,|\hat{a}|^2 = 1, so q is a unit quaternion. For a unit quaternion the inverse is just the conjugate, q^{-1} = q^{*} = (\cos\tfrac{\theta}{2},\ -\sin\tfrac{\theta}{2}\,\hat{a}) — flip the sign of the imaginary part. (In general q^{-1} = q^{*}/|q|^2; here the denominator is 1.)

Step 3 — sandwich. The rotated vector is the imaginary part of the conjugation (or "sandwich") product:

p' = q\,p\,q^{-1} = q\,p\,q^{*}.

Two facts make this legal. First, conjugating a pure quaternion by a unit quaternion gives another pure quaternion — the real part stays 0, so p' decodes back to a genuine vector \mathbf{v}'. Second, it preserves length, |p'| = |q|\,|p|\,|q^{-1}| = |p|, so it can only rotate (or reflect) — and because q deforms continuously to 1 (set \theta = 0), it must be a rotation, never a reflection.

Multiplying it out (using i^2 = j^2 = k^2 = ijk = -1 and |\hat{a}| = 1) and collecting terms gives the vector part

\mathbf{v}' = \cos\theta\,\mathbf{v} + \sin\theta\,(\hat{a}\times\mathbf{v}) + (1-\cos\theta)(\hat{a}\cdot\mathbf{v})\,\hat{a},

which is exactly Rodrigues' rotation formula — rotation of \mathbf{v} by \theta about \hat{a}. The double-angle identities 2\cos^2\tfrac{\theta}{2}-1 = \cos\theta and 2\sin\tfrac{\theta}{2}\cos\tfrac{\theta}{2} = \sin\theta are what convert the half-angles in q into the full \theta in the answer.

Step 4 — why the half-angle? Here is the intuition behind that \theta/2. The quaternion touches the vector twice: once as the left factor q, once as the right factor q^{-1}. Each factor contributes a turn of \theta/2, and the two contributions add — so the vector ends up turned by the full \theta. Put another way: a single-sided product qp would mangle the vector (it generally leaves the pure-quaternion world); the two-sided sandwich is what keeps p' pure, and the price of squeezing from both sides is that each side carries half the angle. (The same half-angle haunts the complex picture the moment you write a rotation as a two-sided product rather than a one-sided one.)

Step 5 — composing rotations is just multiplying. To apply q_1 and then q_2, sandwich twice:

q_2\,(q_1\,p\,q_1^{-1})\,q_2^{-1} = (q_2 q_1)\,p\,(q_2 q_1)^{-1}.

The combined rotation is the single quaternion q_2 q_1apply q_1 first, then q_2 (quaternion multiplication is not commutative, and neither is composing rotations, so the order matters and matches). That is the whole reason engines love them: chaining a hundred rotations is a hundred 4-number products, the result never gimbal-locks, and a tiny renormalisation q \mapsto q/|q| erases any numerical drift back onto the unit sphere.

Let \hat{a} be a unit axis and \theta an angle, and set the unit quaternion q = \left(\cos\tfrac{\theta}{2},\ \sin\tfrac{\theta}{2}\,\hat{a}\right), \qquad |q| = 1. Encoding a vector as the pure quaternion p = (0,\ \mathbf{v}), the following hold.

Open the engine of your choice — Unity, Unreal, Godot, a physics solver, a spacecraft attitude controller — and an object's orientation is a quaternion, not three Euler angles and not a 3\times3 matrix. Three reasons:

And — the subject of the next-but-one page — quaternions interpolate beautifully, so blending one orientation smoothly into another (camera moves, animation transitions) is natural. They are stored as quaternions and, when it's time to draw, converted to a matrix for the GPU.

Spin a vector with the sandwich product

The blue arrow is a fixed vector \mathbf{v}. Choose the axis tilt and the angle \theta: the page builds the unit quaternion q = (\cos\tfrac{\theta}{2},\ \sin\tfrac{\theta}{2}\,\hat{a}) and shows the rotated arrow \mathbf{v}' = q\,(0,\mathbf{v})\,q^{-1} in orange (a 2-D view looking down the axis, where the rotation is a clean turn through \theta). Watch the readout: the quaternion's components carry \theta/2 while the arrow moves through the full \theta — the half-angle, live.