Understanding the quaternion calculator — concept and principle
This calculator adds, subtracts, multiplies and divides quaternions, and gives the conjugate, norm, inverse and unit form of the first quaternion together with the rotation angle and axis it represents. Use it for 3D graphics, game development, robotics, aerospace attitude control and abstract algebra courses.
How it is calculated
A quaternion is q = w + xi + yj + zk with i² = j² = k² = ijk = −1.
- Product q₁q₂: w = w₁w₂ − x₁x₂ − y₁y₂ − z₁z₂; x = w₁x₂ + x₁w₂ + y₁z₂ − z₁y₂; y = w₁y₂ − x₁z₂ + y₁w₂ + z₁x₂; z = w₁z₂ + x₁y₂ − y₁x₂ + z₁w₂.
- Conjugate: w − xi − yj − zk. Norm: |q| = √(w² + x² + y² + z²). Inverse: conjugate ÷ |q|².
- Division: right q₁q₂⁻¹ or left q₂⁻¹q₁, which differ in general.
- Rotation: the unit quaternion cos(θ/2) + sin(θ/2)(axis) rotates v by θ via v′ = q v q⁻¹.
The principle
William Rowan Hamilton found in 1843 that numbers with one real and three imaginary parts could be multiplied consistently if multiplication was allowed to depend on order: ij = k but ji = −k. Quaternions form a number system in which every non-zero element has an inverse, and the norm of a product equals the product of the norms. Unit quaternions describe 3D rotations without the gimbal lock of Euler angles, and two rotations combine by a single multiplication. Since q and −q give the same rotation, the half-angle θ/2 appears in the formula.
Worked example
Default inputs: q₁ = 1 + 2i + 3j + 4k, q₂ = 5 − 6i + 7j + 8k, operation q₁ × q₂.
- w = 5 − (−12) − 21 − 32 = 5 + 12 − 21 − 32 = −36.
- x = 1(−6) + 2(5) + 3(8) − 4(7) = 0.
- y = 1(7) − 2(8) + 3(5) + 4(−6) = −18.
- z = 1(8) + 2(7) − 3(−6) + 4(5) = 60. Result: −36 − 18j + 60k.
- Norm of the result = 72.24956747 = |q₁||q₂| = √30 × √174. For q₁: norm 5.477225575, rotation angle 2·acos(1/√30) ≈ 158.9605302°, axis (2, 3, 4)/√29 ≈ (0.371391, 0.557086, 0.742781).
How to read the result
For multiplication, swapping the order usually changes the answer, so make sure the order matches your application (in many graphics libraries, q₂q₁ means "apply q₁, then q₂"). The rotation angle and axis are read from q₁ after normalising it. A norm of 1 means the quaternion is a pure rotation.
Common mistakes
- Assuming q₁q₂ = q₂q₁.
- Using a non-unit quaternion for rotation without normalising it.
- Forgetting the half angle: a rotation by θ uses cos(θ/2).
- Mixing conventions that store the real part last (x, y, z, w) with ones that store it first.
Frequently asked questions
Why are quaternions used for 3D rotation?
They are compact, avoid gimbal lock and interpolate smoothly between orientations.
What does the conjugate do?
It reverses the imaginary part; for a unit quaternion it is the inverse rotation.
Do q and −q represent the same rotation?
Yes. Both give the same v′ = q v q⁻¹.
Sources: Wolfram MathWorld, "Quaternion" and "Quaternion Rotation"