Skip to content
ISEGORIABenjamin Haire

ISEGORIA / MATH ENCYCLOPEDIA

Quaternions: rotation as multiplication

Hamilton’s four-dimensional numbers: why a rotation is a sandwich with half the angle in each slice, how to interpolate between orientations, and why Euler angles jam where quaternions do not.

Before you begin: Vectors, the dot and cross products, rotation matrices and complex numbers

Predict, manipulate, then check your reasoning against the example and question. Graphs illustrate the mathematics; they do not replace a proof.

1. A rotation is a sandwich

A quaternion is a number \(q = w + x\mathbf i + y\mathbf j + z\mathbf k\) with \(\mathbf i^2 = \mathbf j^2 = \mathbf k^2 = \mathbf{ijk} = -1\). Write a 3D vector \(v\) as the pure quaternion \(x\mathbf i + y\mathbf j + z\mathbf k\); for two pure quaternions, \(uv = -u\cdot v + u\times v\). For a unit axis \(\mathbf n\) and an angle \(\theta\), the unit quaternion \(q = \cos\tfrac{\theta}{2} + \sin\tfrac{\theta}{2}\,\mathbf n\) rotates \(v\) by \(\theta\) about \(\mathbf n\) through the product \(q\,v\,q^{*}\). Drag the tips of \(v\) and \(\mathbf n\). The two small panels split \(v\) into its part along \(\mathbf n\) and its part across \(\mathbf n\), and show what each factor of the sandwich does to each part.

Worked example. Rotate \(v=\mathbf i\) by 90° about \(\mathbf k\): \(q=\tfrac{1}{\sqrt2}(1+\mathbf k)\), so \(q\,\mathbf i=\tfrac1{\sqrt2}(\mathbf i+\mathbf j)\), already a pure vector turned by 45°. Then \(\tfrac1{\sqrt2}(\mathbf i+\mathbf j)\cdot\tfrac1{\sqrt2}(1-\mathbf k)=\tfrac12(\mathbf i+\mathbf j+\mathbf j-\mathbf i)=\mathbf j\), turned by the other 45°.

Watch out. Order matters: \(q_2q_1\) means apply \(q_1\) first, exactly as for matrices, because \(q_2(q_1vq_1^*)q_2^*=(q_2q_1)v(q_2q_1)^*\). And q and −q give the same rotation, since the two signs cancel in the sandwich.

Why can one-sided multiplication v ↦ q v not be a rotation of 3D space?

Because it does not keep v pure: the part of v along n acquires the real part \(-\sin\tfrac\theta2\,(\mathbf n\cdot v)\). Left multiplication is a rotation of four-dimensional space. Only the combination with \(q^*\) on the right cancels the real part and leaves a rotation of the 3D vectors.

Reference: Joan Solà · Quaternion kinematics for the error-state Kalman filter (arXiv:1711.02508)

2. Travelling between orientations

Unit quaternions fill the 3-sphere in four dimensions, and every orientation appears there twice, as q and −q. The shortest way from one orientation to another is an arc of a great circle on that sphere, traversed at constant speed: slerp. Averaging the components and rescaling (nlerp) follows the same arc at uneven speed; averaging Euler angles takes a different, longer route. Watch the tick marks, placed at equal steps of t.

Worked example. For a 150° turn: \(\varphi=75°\), and slerp turns at 150° per unit t throughout. nlerp is fastest at \(t=\tfrac12\), where its speed is \(2\tan(\varphi/2)/\varphi\approx1.17\) times the average: about 176° per unit t.

Watch out. Before interpolating, flip the sign of \(q_B\) if \(q_A\cdot q_B<0\). Otherwise the path goes the long way round, through 360° − Ω, even though \(q_B\) and \(-q_B\) are the same orientation. The Euler path interpolates the z-y-x angles of A and B directly; any angle that crosses ±180° then runs the long way round.

Why is the nlerp path the same arc as slerp, only at a different speed?

The chord from \(q_A\) to \(q_B\) lies in the plane through the origin spanned by them. Rescaling each chord point onto the unit sphere keeps it in that plane, so it lands on the great circle between them. Equal steps along the chord project to unequal steps along the arc, bunched near the ends.

Reference: Ken Shoemake · Animating rotation with quaternion curves (SIGGRAPH 1985)

3. Gimbal lock

Euler angles describe an orientation as three turns in sequence: yaw ψ about z, pitch θ about the carried y axis, roll φ about the body’s own x axis. That is a set of three nested gimbals. When the pitch reaches ±90°, the roll axis swings onto the yaw axis and the three rings lose a dimension between them. The quaternion of the same orientation passes through that point without noticing.

Worked example. At \(\theta=90°\), \(R_y(90°)\) carries \(\hat x\) to \(-\hat z\), so \(R_z(\psi)R_y(90°)R_x(\varphi)=R_z(\psi-\varphi)R_y(90°)\). The orientations \((\psi,\varphi)=(50°,20°)\) and \((80°,50°)\) are identical: only \(\psi-\varphi\) is recorded.

Watch out. Gimbal lock is a flaw of the coordinates, not of the rotation: nothing physical happens to an aircraft at 90° pitch. It is unavoidable for any three-angle chart, because no three coordinates can cover all rotations without a singularity. Unit quaternions escape by using four numbers with one constraint.

Near θ = 90°, what Euler rates would it take to turn the aircraft about the missing axis?

Rates of order \(1/\sigma_{\min}=1/\sqrt{1-|\sin\theta|}\) per unit angular velocity, growing without bound as θ approaches 90°. A controller or integrator working in Euler angles sees yaw and roll rates explode although the motion itself is gentle.

Reference: Joan Solà · Quaternion kinematics for the error-state Kalman filter (arXiv:1711.02508)

Continue exploring

Linear algebra: the geometry of transformationsFourier analysis: functions made of wavesDynamical systems: stability and chaosOptimization: the geometry of the best choiceProbability: learning from uncertaintyGroup theory: symmetry as algebraAlgebraic topology: detecting holesNumerical analysis: when computation misleadsNumber theory: patterns in the integersGraph theory: routes, trees, and networksPartial differential equations: fields in motionInformation theory: uncertainty and codesCalculus of variations: paths and principlesClassical mechanics: motion and forcesElectromagnetism: fields and inductionOptics: rays, waves, and colourThermodynamics: energy, work, and entropyQuantum mechanics: amplitudes and spinComplex analysis: maps, residues, and harmonic fieldsFluid dynamics: flow, pressure, and vorticityStatistics and inference: signals in dataSpecial relativity: space, time, and lightDifferential geometry: curvature and shapeStatistical mechanics: microstates and temperatureMeasure theory: size, approximation, and convergenceMarkov chains: transition, stationarity, and absorptionDifferential forms: circulation, curl, and pullbacksGeneral relativity: curvature, clocks, and lightFunctional analysis: norms, projections, and operatorsPlasma physics: screening, orbits, and wavesLie groups and Lie algebras: continuous symmetryHamiltonian mechanics: phase space and its geometryStochastic processes: Brownian motion and noiseSolid-state physics: waves in a crystalControl theory: feedback, poles, and stabilityLogic and computability: what can be computedHyperbolic geometry: where parallels multiplyRigid-body dynamics: spinning, tumbling, precessingElliptic curves: geometry that addsAtomic physics: orbitals and spectraPush-forward and pullback: integrating through a mapKnot theory: telling tangles apartFractal geometry: dimension between the integersQuantum information: entanglement and its limitsCosmology: the expanding universeCellular automata: computation from local rulesComplex systems: order from many simple partsGalois theory: the symmetry of equationsMagnetism and the Ising model: order from alignmentOscillators and escapements: how a watch keeps timeGears and mechanisms: transmitting motion exactlyQuartz resonators: a crystal that keeps timeLoudspeakers: the moving-coil driverFilters and crossovers: splitting sound between driversRoom acoustics: the room is part of the speakerWavelets: zooming in on a signalLaser physics: light that copies itselfRepresentation theory: groups acting as matricesSemiconductor physics: bands, doping, junctions

Back to the math encyclopedia