How Quaternion Arithmetic Works
A quaternion extends complex numbers into four dimensions: q = w + xi + yj + zk, where w is the real (scalar) part and x, y, z are the coefficients of the imaginary units i, j, k. Those units satisfy i² = j² = k² = ijk = −1, along with ij = k, jk = i, ki = j (and the reverse products negate: ji = −k, kj = −i, ik = −j). This calculator uses those rules to add, subtract, multiply, or dot two quaternions, and to compute the magnitude and inverse of the first one.
How the calculation works
Enter the four components (w, x, y, z) for quaternion 1 and quaternion 2, then choose an operation. Addition and subtraction just combine matching components: (w1±w2, x1±x2, y1±y2, z1±z2). The dot product w1w2 + x1x2 + y1y2 + z1z2 treats each quaternion as a 4D vector and returns a single scalar. The Hamilton product (true quaternion multiplication) expands q1q2 using the i/j/k rules above, giving w = w1w2 − x1x2 − y1y2 − z1z2, x = w1x2 + x1w2 + y1z2 − z1y2, y = w1y2 − x1z2 + y1w2 + z1x2, and z = w1z2 + x1y2 − y1x2 + z1w2. The calculator also reports the magnitude of each quaternion, |q| = √(w² + x² + y² + z²), and the inverse of quaternion 1, q1⁻¹ = q1*/|q1|², where q1* = w1 − x1i − y1j − z1k is the conjugate.
Common mistakes
- Assuming multiplication commutes: unlike ordinary numbers, q1 × q2 generally does not equal q2 × q1 — the Hamilton product depends on order.
- Confusing the dot product with the Hamilton product: the dot product returns a single scalar, while the Hamilton product returns another quaternion; they answer different questions.
- Forgetting the sign flip in the conjugate: only the vector part (x, y, z) changes sign in q* — the real part w stays the same.
- Trying to invert the zero quaternion: if w = x = y = z = 0, the magnitude is zero and the inverse is undefined (division by zero).
Real-world applications
- 3D graphics and game engines use unit quaternions to represent rotations without the gimbal lock that can affect Euler angles.
- Robotics and aerospace attitude-control systems track orientation and angular velocity of vehicles and manipulator arms with quaternions.
- Animation software uses spherical linear interpolation (SLERP) between quaternions to produce smooth rotational motion between keyframes.
- Physics and orbital-mechanics simulations use quaternion multiplication to compose sequential rotations efficiently.