Quaternions

Complex numbers bolt one imaginary unit i onto the reals and, as a reward, multiplication becomes rotation of the plane. The obvious dream is to do the same in three dimensions. William Rowan Hamilton chased it for years — and discovered you cannot do it with two imaginary units, but you can with three. The result is the quaternions, the four-dimensional numbers that run essentially every 3-D rotation in graphics, robotics, and aerospace.

Three imaginary units, one rule

A quaternion extends a + bi with three imaginary units i, j, k:

\mathbf{q} = w + xi + yj + zk, \qquad w, x, y, z \in \mathbb{R}.

Hamilton's entire theory rests on a single line linking the three units, the one he is said to have carved into a bridge:

i^2 = j^2 = k^2 = ijk = -1.

Step 1 — derive the products of pairs. From ijk = -1, multiply on the right by k and use k^2 = -1: ij\,k^2 = -k, so -ij = -k, giving ij = k. The same trick on the others yields the cyclic rule:

ij = k, \qquad jk = i, \qquad ki = j.

Step 2 — discover that order matters. Reverse a product. Since ji = -ij (check: jiijk \to bookkeeping with i^2 = -1 forces the sign flip), we get the anti-cyclic rule:

ji = -k, \qquad kj = -i, \qquad ik = -j.

So ij = k but ji = -k: quaternion multiplication is non-commutative. Swapping the order of a product can flip its sign — which is exactly the behaviour you want from rotations, where doing A then B differs from B then A.

Scalar plus vector

The four numbers split naturally into a real scalar and a 3-D vector of the imaginary parts. Write

\mathbf{q} = (w, \mathbf{v}), \qquad \mathbf{v} = (x, y, z),

treating (i, j, k) as the basis directions (\hat{x}, \hat{y}, \hat{z}). This is the form that makes everything click, because the multiplication rule turns out to be built from the two vector products you already know.

Step 1 — multiply two quaternions as (s_1 + \mathbf{v}_1)(s_2 + \mathbf{v}_2). Distribute the four pieces:

\mathbf{q}_1 \mathbf{q}_2 = s_1 s_2 + s_1 \mathbf{v}_2 + s_2 \mathbf{v}_1 + \mathbf{v}_1 \mathbf{v}_2.

Step 2 — expand the vector-times-vector term. For two pure imaginary quaternions the product splits, by the i,j,k rules above, into a scalar piece and a vector piece. The scalar piece is exactly the negative dot product, and the vector piece is exactly the cross product:

\mathbf{v}_1 \mathbf{v}_2 = -\,\mathbf{v}_1 \cdot \mathbf{v}_2 \;+\; \mathbf{v}_1 \times \mathbf{v}_2.

(The -\mathbf{v}_1\cdot\mathbf{v}_2 comes from the i^2 = j^2 = k^2 = -1 diagonal terms; the \mathbf{v}_1\times\mathbf{v}_2 comes from the cyclic ij = k off-diagonal terms.)

Step 3 — assemble the full product. Collect the scalar pieces and the vector pieces:

(s_1, \mathbf{v}_1)(s_2, \mathbf{v}_2) = \big(\, s_1 s_2 - \mathbf{v}_1 \cdot \mathbf{v}_2,\ \ s_1 \mathbf{v}_2 + s_2 \mathbf{v}_1 + \mathbf{v}_1 \times \mathbf{v}_2 \,\big).

Both classical vector products — the dot and the cross — fall straight out of one quaternion multiplication. And because the cross product obeys \mathbf{v}_1\times\mathbf{v}_2 = -\,\mathbf{v}_2\times\mathbf{v}_1, the product is non-commutative exactly when the two vector parts are not parallel.

Conjugate, norm, inverse

Step 1 — the conjugate flips the vector part:

\mathbf{q}^{*} = (w, -\mathbf{v}) = w - xi - yj - zk.

Step 2 — multiply \mathbf{q}\,\mathbf{q}^{*}. Use the product rule with s_2 = w and \mathbf{v}_2 = -\mathbf{v}. The vector part is w(-\mathbf{v}) + w\mathbf{v} + \mathbf{v}\times(-\mathbf{v}) = \mathbf{0}, and the scalar part is w^2 - \mathbf{v}\cdot(-\mathbf{v}) = w^2 + \mathbf{v}\cdot\mathbf{v}. So the imaginary parts vanish and we are left with a pure real number, the squared norm:

\lVert \mathbf{q} \rVert^2 = \mathbf{q}\,\mathbf{q}^{*} = w^2 + x^2 + y^2 + z^2.

Step 3 — read off the inverse. Divide \mathbf{q}\,\mathbf{q}^{*} = \lVert\mathbf{q}\rVert^2 by the scalar \lVert\mathbf{q}\rVert^2:

\mathbf{q}^{-1} = \frac{\mathbf{q}^{*}}{\lVert \mathbf{q} \rVert^2}.

For a unit quaternion (\lVert\mathbf{q}\rVert = 1) this collapses to the bargain that makes them so cheap in code: \mathbf{q}^{-1} = \mathbf{q}^{*} — to undo the rotation, just negate the vector part. Those unit quaternions are precisely the ones that rotate 3-D space.

On 16 October 1843, walking the towpath of the Royal Canal in Dublin with his wife, Hamilton was struck by the answer he had hunted for a decade: the third imaginary unit, and the rule that ties all three together. Afraid the flash of insight would evaporate, he carved it then and there into the stone of Broom Bridge:

i^2 = j^2 = k^2 = ijk = -1.

The original scratches are long weathered away, but a plaque now marks the spot, and Irish mathematicians retrace the walk every year. The price of three-dimensional rotation was giving up commutativity — Hamilton's genius was to realise that this was a price worth paying, because rotations themselves do not commute.

Multiply two quaternions live

Set the eight coefficients of \mathbf{q}_1 = w_1 + x_1 i + y_1 j + z_1 k and \mathbf{q}_2 = w_2 + x_2 i + y_2 j + z_2 k. The diagram works the rule (s_1 s_2 - \mathbf{v}_1\cdot\mathbf{v}_2,\ s_1\mathbf{v}_2 + s_2\mathbf{v}_1 + \mathbf{v}_1\times\mathbf{v}_2) live, showing each of the four output components — and the running norm — as you move the knobs.