ASF

Quaternions Are the Rotors of Space

July 11, 2026|
A
A

Introduction

On the sixteenth of October 1843, walking with his wife along the Royal Canal in Dublin, William Rowan Hamilton stopped at Broom Bridge and cut a formula into the stone with a knife. He had spent the better part of fifteen years trying to multiply triples of numbers the way the complex numbers multiply pairs, and failing, because there is no way to do it. What he carved was the escape: four numbers rather than three, with three square roots of minus one that refuse to commute,

The carving has worn away and a plaque now marks the spot, but the algebra it names, the quaternions , outlived every argument about it. And there were many arguments. For half a century quaternions were the language in which British physics was written, Maxwell's equations among it; then Gibbs and Heaviside split Hamilton's product into the separate dot and cross products of vector analysis, and the quaternion was left for dead. It returned in the late twentieth century through computer graphics and spacecraft attitude control, where it is now the standard way to store and compose a rotation, and where it is taught as a bag of rules that work for reasons the student is asked to take on faith: multiply like [eq:hamilton], sandwich a vector between and its conjugate, remember the mysterious half-angle, remember that and are the same rotation, and do not ask why.

This article is written to answer the why, and the answer is short enough to state at the outset. Hamilton's quaternions are the even subalgebra of the geometric algebra of space, the algebra built once and in full in the companion piece, Classical Mechanics from Zero, in Two Languages. The three imaginaries are the three basis bivectors of that algebra, the oriented planes of space; a unit quaternion is a rotor, the object that turns a vector by the two-sided sandwich; quaternion conjugation is the rotor reverse; the unit-norm condition is the rotor normalisation . Once the identification is made, every quaternion mystery becomes a fact already proved about rotors. The half-angle is the fingerprint of two reflections. The double cover is the statement that a rotor and its negative sandwich a vector identically. The freedom from gimbal lock is the smoothness of a single group element in place of three stacked angles. Hamilton had found the rotors of space thirty-five years before Clifford wrote down the algebra that contains them, and he found them without the vectors, which is why they arrived wrapped in a mystery that took a century and a half to unwrap.

The plan runs in five parts. Part I rebuilds Hamilton's quaternions on their own nineteenth-century terms, the failed triples, the leap to four, the conjugate and the norm, and the rotation formula as Hamilton and Cayley gave it, so that the object we are going to reinterpret is on the table in its original dress. Part II performs the reinterpretation: it exhibits the even subalgebra , matches its multiplication table to [eq:hamilton] term by term, and proves the isomorphism . Part III turns to rotation and settles the half-angle, the two-to-one cover, the axis, and the storage conventions. Part IV treats interpolation between rotations and the recovery of a quaternion from a rotation matrix, the two operations that make quaternions worth their place in real code. Part V is that code: the native rotation expressions this understanding settles in a data engine, where the mathematics decides what the software is allowed to return.

The reader is assumed to have the companion article within reach, or at least the parts of it that build and its rotors; the geometric product, the bivector, the pseudoscalar, and the sandwich are used here as established, and cross-referenced where they enter. No prior acquaintance with quaternions is presumed. We begin where Hamilton began, with the wish to multiply in three dimensions and the discovery that one cannot.


Part I

1. Hamilton's algebra on its own terms

1.1. The triples that would not multiply

The complex numbers do two jobs at once. As an algebra they are pairs with a multiplication, and as geometry they are the plane, in which multiplication by a unit complex number is rotation by . Hamilton wanted the same coincidence one dimension up: a multiplication on triples , understood as points of space, that would compose rotations the way the complex numbers compose rotations of the plane. He required the multiplication to distribute over addition, to respect lengths in the sense that the modulus of a product is the product of the moduli, and to admit division, so that every non-zero triple has an inverse.

The requirement on the modulus is the obstruction. Writing a triple as with , the product of two such objects throws up a term in , and there is no consistent value for it. Setting or breaks the modulus law; setting and computing the modulus of a product leaves a residue that has nowhere to go inside the triples. The modern statement of the impasse is a theorem: the only finite-dimensional real division algebras are the reals, the complexes, the quaternions, and the octonions, of dimensions one, two, four, and eight, and three is absent from the list. A division algebra on triples does not exist, and Hamilton spent years discovering by hand what the theorem states in one line.

The leap on Broom Bridge was to stop insisting on three. If the stray product has nowhere to go among the triples, give it somewhere to go: a fourth basis element , defined as that product, . The number system becomes four-dimensional, a real part and three imaginary parts, and the modulus law is recovered, at the price Hamilton was reluctant to pay for a long time, that the multiplication does not commute.

1.2. The multiplication and its consequences

Definition (The quaternion algebra).

A quaternion is a real linear combination

of a scalar part and a vector part . The set of all quaternions is written . Addition is componentwise, and multiplication is the bilinear extension of Hamilton's relations

from which the products of distinct units follow,

The relations of [eq:cyclic] are read out of [eq:hamilton-2] with no further input. Multiplying on the right by and using gives ; multiplying on the left by gives ; and the third follows by the same move. Each unit is the product of the other two in cyclic order and minus that product in anticyclic order, the pattern that the cross product would later inherit and that Part II will trace to its source. The three imaginaries anticommute in pairs and each squares to , so no two of them, and no real combination of them, behaves like the single commuting of the complex numbers.

A general product multiplies out. Writing a quaternion as a scalar-and-vector pair with read as an ordinary triple, the product of and collects into

where and are the dot and cross products of the vector parts. This single line is where Gibbs and Heaviside found their vector analysis: the scalar part of [eq:hamilton-product] carries the negative dot product, the vector part carries the cross product, and by keeping the two pieces apart they dispensed with the quaternion and kept its debris. That the one quaternion product already contains both the dot and the cross product is the first sign that it is a more primitive object than either, a sign Part II makes exact by identifying [eq:hamilton-product] with the geometric product restricted to the even grades.

1.3. Conjugate, norm, and inverse

The complex conjugate negates the imaginary part; the quaternion conjugate does the same to all three.

Definition (Conjugate and norm).

The conjugate of is

and the norm is the non-negative real number with

A quaternion is a unit quaternion when .

That is real and equal to the sum of squares is a direct computation from [eq:hamilton-product]: the vector part of is , and the scalar part is . The conjugate reverses the order of a product, , exactly as the transpose reverses a product of matrices, and from this the norm is multiplicative,

which is the length-respecting property Hamilton demanded, now delivered. The multiplicativity of [eq:norm-mult], written in coordinates, is the four-square identity of Euler, that a product of two sums of four squares is again a sum of four squares; the quaternions are the reason it holds.

Every non-zero quaternion has an inverse, and [eq:norm-def] hands it over: since ,

and for a unit quaternion this is . So the unit quaternions are closed under multiplication and inverse: they form a group, and it is a group we will shortly recognise. Because is the equation of the unit sphere in four dimensions, the unit quaternions are that sphere, with quaternion multiplication as a group law on it. Three spheres carry a continuous group structure, those of dimension zero, one, and three, and they are the unit reals, the unit complexes, and the unit quaternions; the coincidence is the same one that makes the division-algebra list stop where it does.

1.4. Rotation, and a half-angle with no explanation

Hamilton and, more sharply, Cayley found how a unit quaternion turns a vector. Identify the triple with the pure quaternion , the one with zero scalar part. The vector of space keeps the bold of the companion article throughout; the pure quaternion is set in plain , for it is an element of , where no grade-one vector lives, and Section 3.1 shows the two to be distinct objects joined by a duality. Then for a unit quaternion the map

sends pure quaternions to pure quaternions, preserves their norm, and is a rotation of the vector . Writing the unit quaternion in the form

the rotation of [eq:quat-sandwich] is the rotation through angle about the axis . The formula is exact and it is what every graphics engine and every attitude filter computes. It also carries two features that are, on the quaternion's own terms, unexplained.

The first is the half-angle. To rotate by the quaternion is built from , and the angle is split once more by the two-sided sandwich, on the left and on the right, so that the halves recombine to the whole. Why the rotation should be assembled from two half-turns rather than applied once is a question the algebra of [eq:hamilton-2] does not answer. The second is the sign. Replacing by in [eq:quat-sandwich] leaves the map unchanged, since the two sign flips cancel, so the quaternion carrying a rotation is determined only up to sign, and the axis-angle form [eq:quat-axis-angle] at and at gives the two opposite quaternions for the one rotation. A rotation by a full turn returns every vector to where it started, yet it sends to . Both features are real, both are used, and both are opaque from inside . Part III will read them straight off the geometry once the quaternion is placed where it belongs.

1.5. The matrix face of the algebra

The classical presentation closes with a matrix realisation, the form in which quaternions most often meet a linear-algebra course and one that foreshadows the identification to come. Sending

with the ordinary complex unit, reproduces [eq:hamilton-2] under matrix multiplication, and identifies the unit quaternions with the group of unimodular unitary complex matrices. The three imaginaries of [eq:pauli] are the Pauli matrices multiplied by , which is the first hint of the double cover: is the group physicists know to be a two-to-one cover of the rotation group. There is also a purely real face, sending each quaternion to a real matrix acting on by left multiplication. These faithful pictures confirm that the algebra is consistent and hand it to whatever tool multiplies matrices. What they do not do is say what the imaginaries are. Part II gives that answer: an oriented plane of ordinary space, an element of the geometry the matrices only encode.


Part II

2. The even subalgebra, and the identification

2.1. The even part of the algebra of space

The companion article builds the geometric algebra of three-dimensional space and lists its eight-dimensional basis by grade, one scalar, three vectors, three bivectors, and one pseudoscalar,

in the cyclic bivector labelling with . The grades split the algebra into even and odd. The even subalgebra is the span of the elements of even grade, the scalar and the three bivectors,

and it is a subalgebra because the geometric product of two even-grade elements is again even: grade adds modulo two under the product, and even plus even is even. It is four-dimensional over the reals. We now compute its multiplication table and compare it with Hamilton's.

Two facts from the companion article do the work. First, each basis bivector squares to ,

because, for instance, using the anticommutation and the contraction . Second, the product of two distinct basis bivectors is the third, with a sign fixed by the cyclic order. Computing one,

where the middle contracts. The other two follow by cycling the indices, giving and .

2.2. Hamilton's imaginaries are the basis bivectors

Equations [eq:bivector-square] and [eq:bivector-product] are Hamilton's relations wearing a minus sign. The sign is absorbed by identifying each imaginary with the negative of a basis bivector.

Proposition (The quaternions are the even subalgebra of space).

The real-linear map fixing the scalar and sending

is an isomorphism of real associative algebras. Under it the quaternion conjugate [eq:conj-def] is the reverse of the companion article, and the quaternion norm [eq:norm-def] is .

The map is a linear bijection between four-dimensional spaces by construction, and to be an algebra isomorphism it need only carry the defining products. Take : it is by [eq:bivector-square], matching , and the same for and . Take the product :

using [eq:bivector-product] at the middle step and at the last. So , and cycling the indices gives and . The remaining relation is the triple product, and it now costs nothing: . Every relation of [eq:hamilton-2] is reproduced, so is an isomorphism.

The claim about conjugation is read off the grades. A quaternion maps to

a scalar plus a bivector. The reverse of the companion article reverses the order of the vector factors in every blade, which leaves the scalar untouched and flips the sign of every bivector, so . Reversion is conjugation. And then

so the rotor normalisation is exactly the unit-quaternion condition. The isomorphism is complete, down to the metric structure that measures lengths.

2.3. What the identification already explains

Three things that were opaque in Part I are now transparent, before we have said a word about rotation.

The non-commutativity of the imaginaries is the non-commutativity of oriented planes under the geometric product. Two distinct bivectors share a line and differ in a second direction, and swapping their order reflects that second direction, which is a sign; there is nothing to explain beyond the anticommutation of orthogonal vectors, which the companion article traces to the contraction axiom. Hamilton's reluctant discovery that was a discovery that planes do not commute.

The appearance of both the dot and the cross product in the single quaternion product [eq:hamilton-product] is the appearance of both grades in the single geometric product. When the companion article multiplies two vectors it gets a scalar plus a bivector, the inner and the outer part together; the even subalgebra inherits the same two-part output, and the pure quaternions, being bivectors, multiply to a scalar plus a bivector whose pieces are, up to the duality of the next paragraph, the dot and the cross of the corresponding vectors. Gibbs and Heaviside cut a bivector-valued product into a scalar and a normal vector and called the two halves separate; the quaternion had them joined because its imaginaries were planes all along.

The pure quaternion is a bivector, not a vector. This is the subtlety that Part III turns to account. Hamilton's identification of the triple with sends it, under , to the bivector , the oriented plane, and not to the vector . The two are exchanged by the pseudoscalar, the Hodge duality of the companion article's Section 1.9: multiplication by carries the bivector to the vector normal to it, and so on. So the quaternion, when it stores a direction, stores the plane perpendicular to that direction, and reaches the direction only by taking the dual. That a rotation should have an axis, a single privileged direction, is the reading of a bivector as its normal vector, and the companion article marks this reading as an accident of three dimensions, the one dimension in which planes and directions are matched in number. The axis of a quaternion rotation is that accident, met again.


Part III

3. Demystifying rotation

3.1. The unit quaternion is a rotor

The companion article's Section 1.10 defines a rotor as an even-grade element , scalar part and bivector part , normalised so that , and it acts on a vector by the sandwich

By [eq:quat-as-rotor] a unit quaternion is precisely such an element, scalar plus bivector with , and by [eq:norm-is-RRtilde] the reverse is the conjugate. So the unit quaternion is the rotor, and the quaternion rotation [eq:quat-sandwich] is the rotor sandwich [eq:rotor-sandwich], with one difference of dress that Section 2.3 already flagged and that is worth stating cleanly.

The rotor sandwich [eq:rotor-sandwich] acts on a vector, a grade-one element . The quaternion sandwich [eq:quat-sandwich] acts on a pure quaternion, which shows to be a bivector , the dual of that same vector. The two actions are the one rotation seen through the duality, because the rotor commutes past the central pseudoscalar: for any rotor and vector ,

since is central and commutes with and . Rotating the vector and then dualising gives the same result as dualising and then rotating, so it does not matter whether the rotor sandwiches the direction or the plane perpendicular to it; the answer transforms the same way. The quaternion chose to sandwich the plane, for the historical reason that Hamilton's imaginaries were bivectors and he had no vectors to sandwich instead. The rotor sandwiches the vector directly. Nothing in the rotation depends on the choice.

3.2. The half-angle is two reflections

The half-angle that Part I could not account for has a one-line explanation in the rotor language. The companion article builds every rotation as a product of two reflections, and a reflection is carried by a single unit vector through the sandwich . Composing the reflection in with the reflection in gives

and the composite is a rotation in the plane the two mirrors share, through twice the angle between them. The rotor is a product of two unit vectors, hence a scalar plus a bivector, and if the angle between the mirrors is then the rotation is through , so the rotor carries in its own angle while producing in the world. Writing the shared plane as the unit bivector with , the rotor is the exponential

the series collapsing to cosine and sine because , exactly as collapses because . Set with the axis imaginary of [eq:quat-axis-angle] and [eq:rotor-exp] becomes , Hamilton's unit quaternion. The half-angle is the record that a rotation is two reflections, and the two-sided sandwich, on the left and on the right, is the record that there were two mirrors. The figure sets the rotor sandwich beside the reflections it is made of.

The exponential form [eq:rotor-exp] also retires the axis as the primary datum. What generates the rotation is the plane , present in the exponent, and the axis is its dual, produced only if one asks for it. The companion article makes the plane the generator of rotations in every dimension, where an axis need not exist; the quaternion, tied to three dimensions, could only ever name the axis, and paid for the privilege with a construction that looked arbitrary.

3.3. The double cover, seen

The sign ambiguity of Part I is the other reflex of the two-sided sandwich, and it is now a one-line computation. Replacing by in [eq:rotor-sandwich],

the two minus signs cancel and the rotation is unchanged. So and carry the one rotation, and the map from unit rotors to rotations is two-to-one. The unit rotors are the sphere of Section 1.3; the rotations are the group ; and the two-to-one map identifies antipodes, presenting as the sphere with each point glued to its opposite, the real projective space . This is the double cover, and it is why appeared in the matrix face [eq:pauli]: the unit quaternions are , the spin group , the connected double cover of the rotations.

The half-angle and the double cover are the same fact told twice. Because the rotor turns through while the world turns through , taking the world once around, , takes the rotor only halfway, , and at the rotor has reached , the negative of where it began, even though every vector is back home. Only at , the world twice around, does the rotor return to . The figure drives a frame through two full turns and shows the rotor's scalar part passing through at the first, the frame identical to its start while the rotor is at the far side of its own sphere.

This is the mathematics behind the plate trick and the belt trick, the physical demonstrations that a twist of a strap cannot be undone without moving the ends, while a twist can: orientation-carrying objects tied to their surroundings track the rotor, not the rotation, and the rotor needs two turns to come home. The spin-one-half of the electron is the same statement in quantum mechanics, that the wavefunction changes sign under a rotation and returns only after . All of it is [eq:sign-cancel], the cancellation of two signs in a two-sided sandwich, read at the level of the group.

3.4. Composition, and the absence of gimbal lock

Two rotations compose by composing their rotors, and the composite rotor is the geometric product of the two,

which is the quaternion multiplication , associative and cheap, sixteen real multiplications for a product against the twenty-seven of a matrix product and with no orthogonality to drift. This is the engineering case for quaternions, and it needs no defence beyond [eq:compose]. What deserves a word is the failure it avoids.

A rotation stored as three Euler angles, a yaw then a pitch then a roll about successive axes, has a configuration in which two of the three axes align and a degree of freedom is lost: at pitch a quarter turn, yaw and roll act in the same plane and only their sum is recoverable, so a smooth motion of the body can demand an unbounded rate in the angles, or freeze one entirely. This is gimbal lock, and it is topological rather than numerical: there is no smooth, singularity-free chart of the whole rotation group by three angles, because is not a product of three circles. The rotor sidesteps the obstruction by not being a chart. It is a single element of the group, moving smoothly wherever the group moves, and the composition [eq:compose] never meets a coordinate edge because there are no coordinates. The figure runs a rotor and, alongside it, an Euler parameterisation into its locked configuration, the rotor turning freely while the angle path stalls.

The double cover is the price of the smoothness. Because is and not a sphere, no continuous choice of a single rotor for each rotation exists over the whole group; any global storage must either double the rotations, which the unit quaternions do, or tear somewhere, which the Euler angles do. The quaternion pays with a sign it must track and receives a parameterisation with no seam. The engineering habit of "flipping the sign to the near hemisphere" before interpolating, met next, is the bookkeeping of that doubling.

3.5. A note on storage order

Because the scalar and the three imaginary parts are stored as four numbers, and because two communities filled the array in opposite orders, a unit quaternion in memory is ambiguous until its convention is named. The scalar-first order places the cosine of the half-angle first and is used by the Eigen constructor, by MuJoCo, and by the Isaac simulators. The scalar-last order places it last and is used by SciPy's rotation module and by the ROS and tf2 robotics stack. The mathematics is indifferent, the isomorphism knows nothing of array indices, but a pipeline that reads one order as the other applies the conjugate rotation composed with a relabelling of axes, silently, and produces a result that is wrong in a way no length check catches, since both orders are unit. The only defence is to make the order explicit at every boundary, which is a design decision Part V takes up in code.


Part IV

4. Interpolation, and recovery from a matrix

4.1. Interpolating on the sphere

A rotation is often wanted part-way between two others, a camera easing from one orientation to another, a joint blending two poses. Averaging the two matrices entrywise leaves the orthogonal group, and averaging the two Euler-angle triples moves through the gimbal singularities; the quaternion offers the correct path, the one that turns at constant rate about a fixed plane. Since unit quaternions are the sphere , the natural interpolation is along the great circle joining them, and it has a name, spherical linear interpolation or slerp.

Let and be unit quaternions and let be the angle between them as points of , so that is their four-dimensional dot product. The great-circle interpolant is

which at is , at is , and in between traces the sphere at unit speed. The rotor language gives [eq:slerp] its meaning. The relative rotor is a rotation through some angle in some plane , so by [eq:rotor-exp] it is , and the interpolant is that relative rotor raised to the fraction ,

scaling the angle of the single relative turn linearly from zero to . Written this way the interpolation is transparently a rotation at constant rate about a fixed plane, the motion a rigid body actually makes when it turns from one attitude to another with nothing pushing it off. The chord interpolation, the straight average renormalised, drifts inside the sphere and speeds up in the middle; the slerp holds the surface.

The double cover matters here. The points and are the same rotation, one at angle from and the other at , so one of the two great-circle arcs is the short way round and the other is the long way. Interpolating without care can send a camera the long way about, three-quarters of a turn to reach an orientation a quarter turn away. The remedy is to test the sign of and negate when it is negative, choosing the representative in the near hemisphere before applying [eq:slerp]. That single sign test is the whole of the "quaternion interpolation gotcha" of the graphics literature, and it is the double cover of [eq:sign-cancel] asking to be resolved by hand because no global choice resolves it once and for all.

4.2. Recovering the quaternion from a rotation matrix

A rotation often arrives as a orthogonal matrix, from a solver, a sensor fusion, a file format, and the quaternion has to be recovered from it. The naive route reads the scalar part from the trace. Since the rotor [eq:rotor-exp] rotates by and an orthogonal matrix has trace , and since , the half-angle identity gives

the off-diagonal differences picking out the antisymmetric part, the bivector, that carries the axis. The formula is correct and it is treacherous. As the rotation approaches a half-turn, , the trace approaches , the scalar approaches zero, and the three divisions by approach division by nothing; the recovered axis, which is real and well defined at exactly a half-turn, is computed as a ratio of two vanishing quantities and loses its significant digits. The instability is not in the rotation, which is perfectly regular at , but in the choice to divide by the one component that happens to vanish there.

The cure is to never divide by a small number, and it is due to Shepperd. The four quantities

are, up to a factor of four, the squares of respectively, and they sum to , so at least one of them is at least and is safe to take a square root of and divide by. Shepperd's method computes whichever of corresponds to the largest of [eq:shepperd-quantities] from its own square root, then obtains the other three from the off-diagonal sums and differences, each divided by the large component just found. Branching on the largest diagonal term keeps every division well conditioned across the whole rotation group, the half-turn included. It is the standard robust conversion, and it is what a library should use in place of [eq:trace-formula].

4.3. When the input is not a rotation

The conversion of Section 4.2 presumes its input is a rotation. Real data does not always oblige: a matrix arrives scaled, or sheared, or reflected, or simply filled with numbers, and the question is what the conversion should do. The geometric-algebra reading gives a clean answer. Shepperd's method yields a unit quaternion exactly when its input lies in , because the quantities [eq:shepperd-quantities] sum to four and reproduce the sum of squares [eq:norm-def] only for a rotation proper; feed it a scaling and the recovered four numbers do not lie on , feed it a reflection, with determinant , and the same. So the norm of the result is a complete and cheap test of membership in the rotation group: compute the quaternion, check that it is unit within a tolerance, and reject the row if it is not. Nothing is silently coerced into a plausible rotation it was never near. This is the null policy that Part V records, the point at which the algebra of Part II decides the behaviour of the software.


Part V

5. Where this lands in code

5.1. Native rotation expressions in a data engine

The occasion for this article was a set of rotation expressions contributed to Daft, the open-source distributed engine for multimodal data. Daft reads the datasets of robotics and embodied AI, DROID, LeRobot, EgoDex, and the MCAP logs of the ROS ecosystem, in which a camera extrinsic or a gripper pose is stored as a bare list of floating-point numbers, a quaternion or a rotation matrix with no operations attached. Turning one into the other, composing two, or measuring the angle between two, meant leaving the engine for a per-row Python function, at a cost the introduction of every such dataset pays. The contribution adds the operations as native columnar expressions: build a rotation matrix from a quaternion or from a six-dimensional representation, recover a quaternion from a matrix, compose and invert and apply quaternions, and measure the geodesic angle between two rotations. The proposal and its rationale are in issue #7250 and the implementation in pull request #7251.

What such a dataset records is worth picturing, because it is exactly the object this article has been about. A logged motion is a sequence of frames, and each frame is a tuple of orientations, one rotor per joint, with nothing dynamical attached: no force, no torque, no mass. The figure below plays one gait cycle of a biped assembled from nothing but its per-joint rotors, the forward kinematics composing them down each limb by the geometric product and placing every segment by the sandwich. At each joint sits the rotation bivector that generates that joint's rotor, the oriented plane of turning: the hip, knee, and ankle flex in the sagittal plane , while the pelvis yaws in , a different plane, so the discs sit at visibly different tilts. Read in pose, each disc tracks its joint angle; read in rate, it tracks the angular speed, largest at heel strike and push-off. The walk is a path through the product of the joint rotor groups, and the pose data is that path sampled. This is the shape the expressions above operate on.

The mathematics of Parts II to IV is the specification that code implements. Three decisions in particular are the article made executable.

5.2. The decisions the algebra forces

The matrix-to-quaternion conversion uses Shepperd's method, not the trace formula, for the reason of Section 4.2: a data engine cannot know in advance that no row of a billion holds a half-turn, and the trace formula loses precision precisely there. Branching on the largest of the four quantities [eq:shepperd-quantities] keeps the conversion accurate across the whole group at the cost of a few comparisons per row, which the columnar loop absorbs.

The null policy is one rule across the module, and it is the rule of Section 4.3: a matrix that is not a rotation returns null rather than a fabricated quaternion, tested by the unit norm of the Shepperd output against a tolerance set safely above floating-point rounding and above the roughly cost of widening a single-precision rotation to double. Zero quaternions, degenerate six-dimensional frames, and non-finite inputs fall under the same policy. The engine returns a rotation only where a rotation was given, and marks the rest absent, so a malformed row propagates as missing data rather than as a plausible and wrong orientation that no downstream check would flag.

The quaternion component order is an explicit argument, defaulting to scalar-last to match SciPy and the robotics stack, with scalar-first available for the Eigen and simulator convention, for the reason of Section 3.5: the choice is a one-way door at the boundary of the system, where reading an array in the wrong order produces a unit quaternion that is silently the wrong rotation. Making the order a named parameter refuses the silent failure and puts the decision where the data's provenance is known.

5.3. What naming the quaternion bought

The thread of this article has been a single identification and its consequences. Hamilton's quaternions are the even subalgebra , the scalar and the three bivectors of ordinary space; a unit quaternion is a rotor; and the sandwich, the half-angle, the double cover, the axis, the freedom from gimbal lock, and the interpolation sign test are each facts about rotors. Each looked like a mystery only while the rotor was described without its geometry.

The identification also draws the line past which the quaternion should not be carried. The rotor is defined in every dimension: the even subalgebra of generates the rotations of -space by the same sandwich, with the plane of rotation as the generator and no axis assumed. The quaternion is the appearance of that construction at , where the even subalgebra happens to be four-dimensional and to close on itself as a division algebra, one of the coincidences the companion article files under the accidents of three dimensions, alongside the cross product and the axis of a rotation. In three dimensions the quaternion is exactly the rotor and there is no harm, and often a real gain in speed and stability, in using the name the engineering world settled on. Above three dimensions the rotor continues and the quaternion does not, and it is the rotor, the even-grade element turning a vector by a two-sided product, that is the thing itself. Hamilton cut the right algebra into the bridge; it took the vectors he did without, and the century that added them, to see which algebra it was.