Math calculator

Quaternion Calculator

ij = k, ji = −k — and that difference is the reason quaternions describe rotations at all.

Quaternion arithmetic

Both orders, every time — because they are different.

Operation

Write 1+2i+3j+4k, or four numbers separated by commas. Fractions are exact.

p = 1 + 2i + 3j + 4k, q = 5 + 6i + 7j + 8k

−60 + 12i + 30j + 24k

q × p gives −60 + 20i + 14j + 32k instead.

p × q

−60 + 12i + 30j + 24k

the order as written

q × p

−60 + 20i + 14j + 32k

a different quaternion

Difference

−8i + 16j − 8k

the commutator, pq − qp

|result|

72.249567

|result|² = 5220

pq = −60 + 12i + 30j + 24k while qp = −60 + 20i + 14j + 32k. They differ by −8i + 16j − 8k, and THIS is the defining feature of quaternions: multiplication depends on the order. It is also exactly why they describe rotations, which do not commute either — turn a book 90° about two different axes in the two orders and it ends up facing differently.

The working

  1. Expand using the multiplication rules. Every product of two basis units is another basis unit with a sign: ij = k, jk = i, ki = j going one way round, and ji = −k, kj = −i, ik = −j going the other.
  2. Real part. a₁a₂ − b₁b₂ − c₁c₂ − d₁d₂ = −60
  3. i, j and k parts. −60 + 12i + 30j + 24k

The rules everything follows from

= −1 = −1 = −1ijk = −1ij = kji = −kjk = ikj = −iki = jik = −j

ij = k but ji = −k. Going one way round i → j → k is positive; going back is negative.

p read as a rotation

Angle

158.96053°

2.7743846 rad

Axis

(0.37139068, 0.55708601, 0.74278135)

|q|² = 30, not a unit

Roll / pitch / yaw

81.869898°, −19.471221°, 135°

ZYX convention

(1,0,0) rotates to

(−0.66666667, 0.66666667, 0.33333333)

by the sandwich product q v q⁻¹

The rotation matrix

The 3 by 3 rotation matrix this quaternion represents
−0.6666670.1333330.733333
0.666667−0.3333330.666667
0.3333330.9333330.133333

The axis is the vector part divided by sin(θ/2), which makes it a unit vector. The rotation is 158.96053° about it, right-handed.

Roll, pitch and yaw in the ZYX (aerospace) convention. There are twelve conventions in use and they give different numbers for the same rotation, so a set of Euler angles means nothing without its convention attached.

|q|² = 30, so this is not a unit quaternion and does not represent a pure rotation on its own — the sandwich product would scale by |q|² as well as rotate. The rotation above is the one for q normalised, q/5.4772256. Keeping rotation quaternions normalised is the single most common thing to get wrong in code that uses them.

−q gives exactly the same rotation as q: negating all four components turns θ into θ − 360°, which is the same orientation. So the map from unit quaternions to rotations is two-to-one. That is why interpolating between two orientations needs a sign check first — without it a slerp can take the 350° route instead of the 10° one.

|pq|² = |p|²|q|² exactly: 30 × 174 = 5220. The norm is multiplicative, which is why a product of two unit quaternions is always a unit — and why composing two rotations never drifts.

The components above are exact fractions, which matters for rotations: a unit quaternion that drifts to |q| = 0.9999 stops being a pure rotation and starts scaling as well.

Conjugate −60 − 12i − 30j − 24k, inverse −1/87 − (1/435)i − (1/174)j − (2/435)k

What this tool shows

Both products every time, both quotients, and the rotation a unit quaternion actually represents.

  • Both orders of every product, with the commutator between them
  • Both quotients, p·q⁻¹ and q⁻¹·p, rather than one labelled p/q
  • Axis, angle, rotation matrix and Euler angles from a unit quaternion
  • Gimbal lock reported when the Euler extraction is genuinely undetermined
Both pq and qp, every time Exact rational components Rotation, matrix and Euler Free, no signup

Free, no signup — exact components, so a unit stays a unit.

Updated 6 September 2026 · Works in any browser, no installation

Quaternion multiplication does not commute: ij = k, but ji = −k. 1 + 2i + 3j + 4k times 5 + 6i + 7j + 8k is −60 + 12i + 30j + 24k one way round and −60 + 20i + 14j + 32k the other — a difference of −8i + 16j − 8k.

At a glance

Formula shown
i\u00b2 = j\u00b2 = k\u00b2 = ijk = \u22121. Everything else follows, including ij = k and ji = \u2212k.
Scenario support
Quaternions with rational components, and unit quaternions read as rotations.
Educational estimate
Planning support from the values you enter — not professional advice.

One line of rules, and everything follows

Hamilton’s relation is i² = j² = k² = ijk = −1, and every product of two basis units follows from it:

i² = −1, j² = −1, k² = −1, ijk = −1, ij = k, ji = −k, jk = i, kj = −i, ki = j, ik = −j

Read that as a cycle. Going forwards round i → j → k → i the products are positive; going backwards they are negative. i × j = k and j × i = −k, which is the same fact stated twice.

Legend has it Hamilton carved this on a Dublin bridge in 1843, after fifteen years of trying to multiply triples and failing. The reason he failed is that it cannot be done: there is no three-dimensional division algebra, and the fourth component is not decoration.

Order matters, and that is the subject rather than a caveat

pq = −60 + 12i + 30j + 24k while qp = −60 + 20i + 14j + 32k. They differ by −8i + 16j − 8k, and THIS is the defining feature of quaternions: multiplication depends on the order. It is also exactly why they describe rotations, which do not commute either — turn a book 90° about two different axes in the two orders and it ends up facing differently.

This is exactly the behaviour rotations have. Take a book, rotate it 90° about the vertical axis and then 90° about the horizontal one; now do the two in the other order. The book ends up facing differently, and no amount of care changes that.

So a system that describes rotations must not commute, and one that does cannot be describing them. That is the strongest single argument for quaternions over any three-number scheme.

Addition is a different story: 1 + 2i + 3j + 4k + 5 + 6i + 7j + 8k gives 6 + 8i + 10j + 12k in either order. Addition IS commutative — quaternions form an ordinary abelian group under it. It is only multiplication that does not commute.

Two quotients, and p/q is ambiguous

p·q⁻¹ and q⁻¹·p are DIFFERENT quaternions, so "p divided by q" is ambiguous unless you say which side. Both are given above. In a rotation context the two correspond to composing in the body frame and in the world frame, which is a real distinction and not a notational one.

For 1 + 2i + 3j + 4k and 5 + 6i + 7j + 8k: p·q⁻¹ = 35/87 + (4/87)i + (8/87)k while q⁻¹·p = 35/87 + (8/87)j + (4/87)k. Two different quaternions, and writing “p/q” does not say which.

The inverse itself is unambiguous: q⁻¹ = q̄/|q|², the conjugate over the norm squared — the same construction as for complex numbers, and available for every non-zero quaternion. It is only the SIDE you multiply on that has to be specified.

In practice this is the difference between composing a rotation in the body frame and in the world frame, which is a real modelling distinction that silently produces wrong results when it is got backwards.

Rotations, and where the half angle comes from

A unit quaternion q = cos(θ/2) + sin(θ/2)·(unit axis) rotates a vector v by the sandwich product q v q⁻¹, through θ about that axis.

The axis is the vector part divided by sin(θ/2), which makes it a unit vector. The rotation is 120° about it, right-handed. For 1/2 + (1/2)i + (1/2)j + (1/2)k, (1,0,0) rotates to (0, 1, 0) — the cyclic permutation x → y → z.

The half angle is not a convention. A vector v is rotated by the sandwich product q v q⁻¹, treating v as a quaternion with zero real part. Applying q on both sides is why the half-angle appears in the definition: the rotation gets applied twice over, so the angle inside q has to be half of the one you want.

The axis is the vector part divided by sin(θ/2), which makes it a unit vector. The rotation is 90° about it, right-handed. which is a quarter turn about the vertical axis, and its matrix is the one you would write by hand for that rotation.

q and −q are the same rotation

−q gives exactly the same rotation as q: negating all four components turns θ into θ − 360°, which is the same orientation. So the map from unit quaternions to rotations is two-to-one. That is why interpolating between two orientations needs a sign check first — without it a slerp can take the 350° route instead of the 10° one.

This is the source of the classic slerp bug. Interpolating from q₁ to q₂ along the shorter arc requires checking the sign of their dot product first; without that check the interpolation can take the 350° route to an orientation 10° away, and the object spins almost all the way round.

It is also why normalisation matters so much in code. A unit quaternion represents a pure rotation; drift away from unit length and the sandwich product starts scaling as well as rotating. Exact arithmetic here means a quaternion entered as a unit stays one, which floating-point accumulation does not guarantee.

Why not Euler angles

Three numbers are enough to specify an orientation, so Euler angles look like the economical choice. They fail in one specific configuration and the failure is structural rather than numerical.

GIMBAL LOCK: the pitch is at ±90°, where the roll and yaw axes line up and only their sum is determined. The individual values above are one of infinitely many equivalent splits — the Euler representation has genuinely lost a degree of freedom here. The quaternion has not; this is the failure mode quaternions exist to avoid.

At pitch ±90° the roll and yaw axes align, only their sum is determined, and one degree of freedom disappears from the representation. The orientation is perfectly well defined; the three numbers describing it are not. That is gimbal lock, and it is what brought the Apollo guidance platform close to unusable configurations.

Quaternions have no such configuration, which is why flight software, robotics and every 3D engine use them internally and convert to Euler angles only for display. The tool reports the singular case rather than returning one of the infinitely many equivalent splits as though it were the answer.

Sources and methodology

Quaternion algebra and the rotation correspondence are standard; the references below carry the canonical statements.

Method. Every figure on this page comes from src/lib/quaternion.ts, which performs the Hamilton product on exact rational components. Both orders are computed on every operation, and the commutator is their difference rather than a separate calculation. The rotation matrix, axis-angle and Euler extraction use double-precision trigonometry; the matrix is checked to be orthogonal with determinant 1. That engine is verified on every change against 59 hand-written assertions, including that the basis multiplication table is reproduced by the general product (ij = k, ji = −k, ijk = −1), and that every rotation matrix produced is a proper rotation. The count and the per-case breakdown are published on the formula verification page.

Related calculators

Where this goes next:

Complex NumberAdd, subtract, multiply, divide and raise complex numbers to powers exactly — (1+i)^8 is 16, not 15.999999999999996 — with the conjugate trick shown as the working for division.
Complex RootAll n roots of any complex number by De Moivre, exact wherever a root is a Gaussian rational, arranged as the regular n-gon they form, with the sum and product checked.
Complex ConjugateThe conjugate, and everything it does: the sum, difference, product and quotient identities computed on your number, the reflection geometry, and the real quadratic behind conjugate root pairs.
System of EquationsSolve linear systems in up to six unknowns with exact fractions — row operations, the matrix form, Cramer’s rule, and the parametric family when there is no single answer.
Cubic EquationSolve any cubic exactly when it has a rational root — deflate and finish with the quadratic formula — and by the trigonometric form when it does not, with the discriminant saying which case you are in.
Binomial Coefficientn choose k exactly on big integers, by the multiplicative formula that never builds a number bigger than the answer — with Pascal's rule, the row it sits in, and permutations beside it.

More in Math, or browse all calculators.

Read the guide

Quaternions extend the complex numbers, and the extension costs commutativity. The Complex Number Calculator covers the two-dimensional case where multiplication still commutes and rotations are still just angles adding.

Educational use disclaimer

This calculator performs exact arithmetic on quaternions with rational components. The rotation reading — axis, angle, matrix and Euler angles — uses double-precision trigonometry, and the Euler extraction reports the gimbal-lock configuration rather than returning one of the infinitely many equivalent splits as though it were determined. Euler angles are given in the ZYX (aerospace) convention; twelve conventions are in use and they disagree.

How we calculate · Found an error? email us

Authorship & verification

Written and maintained by , a business operator who builds spreadsheet-based calculators.

What's changed (3 updates)

Published 6 September 2026

  1. Published the quaternion page: exact rational arithmetic that computes BOTH pq and qp every time, because non-commutativity is the subject rather than a footnote.
  2. Gives both quotients, p·q⁻¹ and q⁻¹·p, rather than pretending p/q is unambiguous — the distinction is body frame against world frame, not notation.
  3. Reads a unit quaternion as a rotation with axis, angle, matrix and Euler angles, and names the gimbal-lock case instead of returning a plausible wrong answer there.

Add this calculator to your site

Responsive embed — and private: nothing your visitors type leaves their browser.