What is a Quaternion Calculator?
A quaternion is a four-dimensional number written as \(q = w + xi + yj + zk\), where w is the scalar (real) part and (x, y, z) is the vector (imaginary) part. Quaternions are widely used in 3D computer graphics, robotics, aerospace and physics to represent rotations without the gimbal-lock problems of Euler angles. This calculator multiplies two quaternions, and also reports the norm of each input and the conjugate of the first.
How to Use It
Enter the four components (w, x, y, z) for each quaternion q1 and q2. The calculator returns the Hamilton product q1 × q2 as a new quaternion, the magnitude (norm) of both inputs, and the conjugate of q1. Quaternion multiplication is not commutative: in general q1 × q2 ≠ q2 × q1, so order matters.
The Formula Explained
The Hamilton product combines a scalar part and a vector part.
$$\begin{gathered} q_1 q_2 = (w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2) + (w_1 x_2 + x_1 w_2 + y_1 z_2 - z_1 y_2)\,i \\ + (w_1 y_2 - x_1 z_2 + y_1 w_2 + z_1 x_2)\,j + (w_1 z_2 + x_1 y_2 - y_1 x_2 + z_1 w_2)\,k \\[1.5em] \text{where}\quad \left\{ \begin{aligned} q_1 &= \text{w}_1 + \text{x}_1\,i + \text{y}_1\,j + \text{z}_1\,k \\ q_2 &= \text{w}_2 + \text{x}_2\,i + \text{y}_2\,j + \text{z}_2\,k \end{aligned} \right. \end{gathered}$$The scalar result is w₁w₂ minus the dot product of the vector parts. The vector result is w₁v₂ + w₂v₁ plus the cross product v₁ × v₂. The norm is the Euclidean length \(\sqrt{w^2+x^2+y^2+z^2}\), and the conjugate simply negates the vector components: \(q^{*} = (w, -x, -y, -z)\).
$$\lVert q_1 \rVert = \sqrt{\text{w}_1^{2} + \text{x}_1^{2} + \text{y}_1^{2} + \text{z}_1^{2}}$$$$\lVert q_2 \rVert = \sqrt{\text{w}_2^{2} + \text{x}_2^{2} + \text{y}_2^{2} + \text{z}_2^{2}}$$$$q_1^{*} = \text{w}_1 - \text{x}_1\,i - \text{y}_1\,j - \text{z}_1\,k$$
Worked Example
Let q1 = (1, 2, 3, 4) and q2 = (5, 6, 7, 8). The scalar part is \(1\cdot5 - 2\cdot6 - 3\cdot7 - 4\cdot8 = 5 - 12 - 21 - 32 = -60\). The i part is \(1\cdot6 + 2\cdot5 + 3\cdot8 - 4\cdot7 = 6 + 10 + 24 - 28 = 12\). The j part is \(1\cdot7 - 2\cdot8 + 3\cdot5 + 4\cdot6 = 7 - 16 + 15 + 24 = 30\). The k part is \(1\cdot8 + 2\cdot7 - 3\cdot6 + 4\cdot5 = 8 + 14 - 18 + 20 = 24\). So q1 × q2 = (−60, 12, 30, 24).
Quaternion Basis Multiplication Table (i, j, k)
Every quaternion product reduces to the products of the basis elements 1, i, j, k. In the table below, the row is the left factor and the column is the right factor.
| Left × Right | 1 | i | j | k |
|---|---|---|---|---|
| 1 | 1 | i | j | k |
| i | i | −1 | k | −j |
| j | j | −k | −1 | i |
| k | k | j | −i | −1 |
Defining relations: \(i^2 = j^2 = k^2 = ijk = -1\). From these follow \(ij = k\), \(jk = i\), \(ki = j\), and the reversed products \(ji = -k\), \(kj = -i\), \(ik = -j\).
Why multiplication is non-commutative: for the distinct pairs among i, j, k, the table is anti-symmetric. Swapping the order flips the sign, so \(ij = -ji\), \(jk = -kj\) and \(ki = -ik\). The diagonal entries are all −1. Because of this sign flip, \(q_1 q_2 \neq q_2 q_1\) in general. The order of the factors matters in the Hamilton product.
Interpreting Norm, Conjugate and Product Results
- Norm: \(\|q\| = \sqrt{w^2 + x^2 + y^2 + z^2}\). The norm is multiplicative: \(\|q_1 q_2\| = \|q_1\|\,\|q_2\|\).
- Conjugate: \(q^* = w - xi - yj - zk\). Multiplying a quaternion by its conjugate gives a real number: \(q\,q^* = q^*q = \|q\|^2\).
- Inverse: \(q^{-1} = \dfrac{q^*}{\|q\|^2}\). For a unit quaternion (norm = 1), the inverse is simply the conjugate.
- Unit quaternion = 3D rotation: a rotation by angle \(\theta\) about a unit axis \(u = (u_x, u_y, u_z)\) is \(q = \cos(\theta/2) + \sin(\theta/2)\,(u_x i + u_y j + u_z k)\). A vector \(v\), written as a pure quaternion, is rotated by \(v' = q\,v\,q^*\).
- Pure quaternion: a quaternion with \(w = 0\), such as \(xi + yj + zk\). It is used to represent 3D vectors.
- Double cover: \(q\) and \(-q\) represent the same rotation. They are two different quaternions describing one orientation.
- Composing rotations: with the convention \(v' = q\,v\,q^*\), the product \(q_1 q_2\) applies \(q_2\) first and then \(q_1\). Some libraries use the opposite convention, so check yours.
- Renormalizing: after many successive multiplications, floating-point rounding makes the norm drift away from 1. Divide by the norm, \(q/\|q\|\), to restore a valid rotation.
If the norm of a product is not what you expect, check that each input is a unit quaternion. By multiplicativity, the product of two unit quaternions has norm 1, up to rounding.
Quaternion Terminology
- Quaternion
- A number of the form \(q = w + xi + yj + zk\) with real coefficients w, x, y, z. The units satisfy \(i^2 = j^2 = k^2 = ijk = -1\).
- Scalar (real) part w
- The coefficient w of 1. It is the part that does not involve i, j or k.
- Vector (imaginary) part (x, y, z)
- The coefficients of i, j and k, treated as a 3D vector.
- Hamilton product
- The associative but non-commutative product of two quaternions, built from the basis rules and distributivity. It is the operation this calculator computes as \(q_1 q_2\).
- Conjugate
- \(q^* = w - xi - yj - zk\). The vector part changes sign.
- Norm (magnitude)
- \(\|q\| = \sqrt{w^2 + x^2 + y^2 + z^2}\), the length of q as a 4D vector.
- Unit quaternion
- A quaternion with norm 1. Unit quaternions represent 3D rotations.
- Pure quaternion
- A quaternion with zero scalar part (\(w = 0\)). It is often used to represent a point or vector in 3D.
- Inverse
- The quaternion \(q^{-1} = q^*/\|q\|^2\) satisfying \(q\,q^{-1} = 1\). It exists for every nonzero quaternion.
- Non-commutativity
- In general \(q_1 q_2 \neq q_2 q_1\), because \(ij = -ji\) and so on. Rotations in 3D do not commute either.
- Gimbal lock
- A singularity of Euler-angle representations. When two rotation axes align (for example at a pitch of ±90°), one degree of freedom is lost. Quaternions do not suffer from it.
FAQ
Is quaternion multiplication commutative? No. Because of the cross-product term, q1 × q2 generally differs from q2 × q1.
What is a unit quaternion? A quaternion with norm equal to 1. Unit quaternions represent pure rotations in 3D space.
How do I rotate a vector? Treat the vector as a quaternion with w = 0 and compute \(q \cdot v \cdot q^{*}\), where q is a unit quaternion encoding the rotation.