HuntsvilleEngineers mark
HE Reference Shelf — huntsvilleengineers.com
The Reference Shelf · Geometry & Mechanics

Quaternions

Four numbers that store a 3D orientation with no singularities — the reason your IMU can point straight up without the math falling apart.

Also known as: unit quaternions · Euler-Rodrigues parameters · attitude quaternion · quaternion rotation

The formula (the core equation(s), each with a one-line reading of what it says)

q = w + x·i + y·j + z·k,   where i² = j² = k² = i·j·k = −1

Reads: a quaternion is one real part and three imaginary parts, and the whole algebra follows from that single rule Hamilton carved into a bridge — note it forces i·j = k but j·i = −k, so order matters.

q = ( cos(θ/2),  u·sin(θ/2) ),   with |u| = 1 and w² + x² + y² + z² = 1

Reads: a unit quaternion encodes a rotation by angle θ about axis u — but with the half angle, which is the detail behind most quaternion bugs. A 90° rotation about z is q = (0.7071, 0, 0, 0.7071).

v' = q · (0, v) · q⁻¹

Reads: to rotate a vector, promote it to a quaternion with zero real part and sandwich it. Rotating (1,0,0) by the 90°-about-z quaternion above gives (0,1,0), as it should.

q_total = q₂ · q₁        (apply q₁ first, then q₂)

Reads: composing rotations is one quaternion multiply — 16 multiplications and 12 additions, versus 27 and 18 for the equivalent 3×3 matrix product, and four stored numbers instead of nine.

θ = 2·atan2( √(x² + y² + z²), w ),   u = (x, y, z) / sin(θ/2)

Reads: axis and angle come back out whenever you need something human-readable. Use atan2, not 2·acos(w)acos loses precision badly as w approaches 1, exactly where small attitude errors live.

Where you meet it (2-4 concrete engineering situations, specific: bench, test stand, review board)

The IMU on the bench. Every AHRS and sensor-fusion filter worth flying — EKF, Mahony, Madgwick — carries its attitude state as a quaternion and streams one out over the serial port. When you tumble the unit through vertical and your roll/pitch/yaw plot goes berserk at 90° pitch, the filter is fine. The Euler-angle display is singular there; the quaternion underneath never blinked. Plot the four quaternion components when debugging, not the angles.

The ADCS design review. Spacecraft attitude control loops command slews as an error quaternion: q_err = q_target · q_current⁻¹, and the controller torques the vehicle to drive the vector part to zero. The review-board question to be ready for: what happens when the scalar part of q_err goes negative? If the software doesn't negate the quaternion, the vehicle takes the 350° route instead of the 10° one. That check is one if statement, and its absence has burned real propellant.

The integration lab, two vendors, one interface. Your IMU vendor ships quaternions scalar-last (x, y, z, w) in the JPL convention; your simulation framework expects scalar-first (w, x, y, z) Hamilton convention. Everything runs, nothing errors, and the visualized attitude is wrong in a way that looks almost right until someone commands a large yaw. Convention mismatch is the number-one quaternion integration defect, and it is invisible at small angles.

Telemetry post-processing. A recorded attitude history will occasionally jump from q to −q — same physical orientation, opposite signs. Any rate you difference numerically across that flip explodes. The fix is a continuity pass: if the dot product of successive quaternions is negative, negate the new one.

How it works (the real substance — behavior, gotchas, limits of validity, the mistake people make)

The unit quaternions live on a 4D sphere, and that sphere wraps around the space of 3D rotations exactly twice: q and −q are the same physical attitude [7]. That double cover is why the half angle appears — the sandwich product q·v·q⁻¹ applies q twice, quadratically, so each application carries θ/2 and the signs cancel. It is also why there is no gimbal lock: the sphere has no seams. Any three-number attitude representation — any Euler sequence, any set of three angles — is degenerate somewhere, the way longitude is meaningless at the North Pole. The Apollo guidance platform hit this physically: its three-gimbal IMU lost a degree of freedom near 90° pitch, threw a warning at 70°, and Michael Collins famously asked Houston for a fourth gimbal for Christmas [8][9]. Quaternions spend a fourth number instead of a fourth gimbal, plus one constraint (|q| = 1), and buy a representation with no bad orientation anywhere.

What you get for that trade:

  • Composition is cheap and stable. Chaining ten thousand incremental rotations as matrices lets the matrix drift away from orthogonality, and re-orthogonalizing a matrix is genuinely awkward. A quaternion drifts too — ten thousand successive single-precision multiplies took a unit quaternion's norm to 0.9999994 in a quick test — but the repair is one line: divide by the norm. Renormalize every cycle in a flight loop; it costs a square root.
  • Interpolation actually works. Slerp — spherical linear interpolation — sweeps between two attitudes at constant angular rate along the shortest arc. Interpolating Euler angles component-wise produces paths that wobble and can swing near singularities; slerp cannot.
  • Integration is clean. Body rates ω from the gyro propagate the attitude through q̇ = ½ · q · (0, ω) — the workhorse equation inside every AHRS. That ½ is the half-angle again; dropping it gives attitude that runs at twice the true rate, a factor-of-two bug that shows up in every new implementation eventually.

The mistakes, in the order people make them:

  1. Convention roulette. Scalar-first vs scalar-last storage; Hamilton vs JPL multiplication handedness; rotating the vector vs rotating the frame (one is the conjugate of the other). None of these produce errors or warnings — only wrong attitudes. Write the convention on the ICD and unit-test one known 90° rotation across every interface.
  2. Treating q like a vector. Averaging two quaternions component-wise and normalizing is only acceptable when they are close together; averaging q with what happens to be stored as −q gives garbage. Fix signs first, or use a proper averaging method.
  3. Forgetting multiplication doesn't commute. q₂·q₁ ≠ q₁·q₂ — rotations in 3D don't commute and the algebra honors that. Swapped order compiles fine and fails in hardware.
  4. Extracting angles carelessly. 2·acos(w) for the rotation angle is ill-conditioned near zero rotation, where attitude errors live. Use the atan2 form.

Limit of validity: none in the rotation sense — every 3D rotation has exactly two unit quaternions and every unit quaternion is a rotation. The real limits are human. Nobody reads a quaternion in a meeting; convert to Euler angles at the display layer and keep quaternions everywhere else. And a quaternion stores orientation only — position needs its own three numbers, or the step up to dual quaternions.

History (who derived it and when, told as a short story with inline [n] citations)

The pieces existed before the algebra had a name. Euler, in a letter to Goldbach dated May 4, 1748, wrote down the four-square identity — the fact that a product of two sums of four squares is itself a sum of four squares — which is precisely the statement that quaternion norms multiply, ninety-five years before quaternions [5][2]. In 1840, Olinde Rodrigues — a French banker doing mathematics on the side — published a purely geometric derivation of how two finite rotations compose, in a paper in the Journal de Mathématiques Pures et Appliquées; his four-parameter composition rule is, in modern terms, unit-quaternion multiplication, three years early [3][4]. That is why the attitude community calls the four numbers the Euler–Rodrigues parameters.

The algebra itself arrived on October 16, 1843. William Rowan Hamilton had spent roughly a decade trying to multiply number triples — his children reportedly asked at breakfast, "Well, Papa, can you multiply triplets?" and the answer was always no [1][2]. Walking along the Royal Canal in Dublin toward a Royal Irish Academy meeting, he saw that the trick was four components, not three, and cut the defining relation i² = j² = k² = ijk = −1 into the stone of Broome Bridge on the spot [1][2]. He spent the rest of his life developing the subject.

Quaternions then lost the notation war. From the mid-1880s, the vector analysis of Gibbs and Heaviside — which openly borrowed the dot and cross products out of the quaternion product — displaced them as the working language of physics and engineering [6][2]. They came back through the industries that could not tolerate singularities: spacecraft attitude control systems are routinely commanded in quaternions, IMU filters carry them as state, and computer graphics adopted them for smooth rotation — Tomb Raider in 1996 is cited as an early mass-market case [6][2]. Hamilton's bridge graffiti turned out to be flight software.

Related tools (bullet list of HE calculator slugs that use or neighbor this topic, as /tools/ links)

Sources

  1. https://mathshistory.st-andrews.ac.uk/Biographies/Hamilton/
  2. https://en.wikipedia.org/wiki/History_of_quaternions
  3. https://mathshistory.st-andrews.ac.uk/Biographies/Rodrigues/
  4. https://en.wikipedia.org/wiki/Olinde_Rodrigues
  5. https://en.wikipedia.org/wiki/Euler%27s_four-square_identity
  6. https://en.wikipedia.org/wiki/Quaternion
  7. https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation
  8. https://en.wikipedia.org/wiki/Gimbal_lock
  9. https://apollojournals.org/alsj/gimbals.html

Written by HE in our own words from the cited sources — engineering judgment included, your stamp still required. All entries →

★ The Reference Shelf

Reading is free. The shelf is for cardholders.

Your library card is an email address: pin it to your shelf, print the card, take the FE/PE quick-reference pack, read the Huntsville history. The shelf remembers what you reach for.

Already on the list? Enter with your subscribed email →