Quaternion Calculator - Multiply, Conjugate, Rotate
Use this quaternion calculator to multiply two quaternions, compute the conjugate, norm, or inverse, or convert a unit quaternion to a 3x3 rotation matrix for 3D rotations.
Quaternion Calculator
Results
What Is Quaternion Calculator?
A quaternion calculator is a math tool that performs quaternion arithmetic and converts a quaternion into a 3x3 rotation matrix. Enter two quaternions q = w + xi + yj + zk and pick an operation (multiply, add, conjugate, norm, inverse, or rotation matrix), and the calculator returns the w, x, y, z components.
- • Multiplying two quaternions: Use the Hamilton product mode to combine two quaternions, the standard operation for chaining rotations in 3D engines and robotics.
- • Computing conjugate and inverse: Compute the conjugate to negate the vector part, or the inverse to undo a rotation by dividing the conjugate by the squared norm.
- • Converting to a 3D rotation matrix: Pick the rotation matrix mode to get a 3x3 matrix that represents the same rotation as a unit quaternion.
- • Verifying unit quaternions: Use the norm mode to confirm a quaternion is a unit quaternion (|q| = 1) before passing it to a function that assumes unit length.
A quaternion is a four-part number q = w + xi + yj + zk, with real part w and vector part (x, y, z). The rule i^2 = j^2 = k^2 = ijk = -1 is what Hamilton carved into the Brougham Bridge in 1843, and the Hamilton product that follows from it is not commutative.
Most people who open a quaternion calculator are combining two rotations, taking the conjugate or inverse, or converting a unit quaternion to a 3x3 rotation matrix.
For working with the related 2D representation of complex numbers, our complex number calculator is the natural companion and follows the same Hamilton-style scalar and vector reasoning at one fewer dimension.
How Quaternion Calculator Works
The calculator reads the four components of q1 and (when needed) q2, then applies the matching formula. Addition is componentwise, multiplication uses the Hamilton product, the conjugate flips the sign of the vector part, the norm takes the square root of the sum of squares, the inverse divides the conjugate by the squared norm, and the rotation matrix is built from the unit-length version of q1.
- w1, x1, y1, z1: Scalar and i, j, k components of the first quaternion q1.
- w2, x2, y2, z2: Scalar and i, j, k components of q2. Used only in add and multiply modes.
- operation: Which operation to perform: add, multiply, conjugate, norm, inverse, or rotationMatrix.
The rotation matrix mode first normalizes q1 to unit length, then applies the standard formula. The 3x3 matrix has mirror-image off-diagonal pairs: m01/m10, m02/m20, m12/m21.
The formulas above match the Wikipedia quaternion article, and the conjugate, norm, and inverse definitions match the Wolfram MathWorld quaternion entry.
Identity check: (1, 0, 0, 0) * (1, 2, 3, 4)
q1 = (1, 0, 0, 0), q2 = (1, 2, 3, 4), multiply
Real: 1*1 - 0*2 - 0*3 - 0*4 = 1. i: 1*2 + 0*1 + 0*4 - 0*3 = 2. j: 1*3 - 0*4 + 0*1 + 0*2 = 3. k: 1*4 + 0*3 - 0*2 + 0*1 = 4.
Result: (1, 2, 3, 4). The identity leaves q2 unchanged.
The identity quaternion (1, 0, 0, 0) leaves every other quaternion unchanged, a quick way to confirm the Hamilton product is wired correctly.
Basis check: i * j = k
q1 = (0, 1, 0, 0), q2 = (0, 0, 1, 0), multiply
Real: 0*0 - 1*0 - 0*1 - 0*0 = 0. i: 0*0 + 1*0 + 0*0 - 0*1 = 0. j: 0*1 - 1*0 + 0*0 + 0*0 = 0. k: 0*0 + 1*1 - 0*0 + 0*0 = 1.
Result: (0, 0, 0, 1), confirming i * j = k.
Multiplying two pure basis quaternions reproduces the i, j, k multiplication table, a clean way to verify the calculator uses the standard signs.
According to Wikipedia, the Hamilton product of q1 = w1 + x1 i + y1 j + z1 k and q2 = w2 + x2 i + y2 j + z2 k has scalar part w1 w2 - x1 x2 - y1 y2 - z1 z2 and the i, j, k coefficients follow the same sign pattern produced by the rule i^2 = j^2 = k^2 = ijk = -1.
According to Wolfram MathWorld, the conjugate of a quaternion is the same number with the sign of the three imaginary components flipped, the norm is the square root of the sum of the four squared components, and the inverse is the conjugate divided by the squared norm.
The rotation matrix mode pairs naturally with a polar conversion because both take a 2D or 3D representation and turn it into a magnitude plus an angle, and the cartesian to polar calculator covers the 2D version of the same idea in one step.
Key Concepts Explained
Four short ideas cover the rest of the calculator.
Scalar and Vector Parts
Every quaternion splits into a real number w (the scalar part) and a 3D vector (x, y, z) (the vector part).
Hamilton Product
The product uses i^2 = j^2 = k^2 = ijk = -1. The scalar part subtracts three dot-product pairings, and the i, j, k components are built from a mix of dot and cross products. Not commutative.
Conjugate and Norm
The conjugate flips the sign of the vector part. The norm is the square root of the sum of the four squared components. For a unit quaternion the conjugate equals the inverse.
Unit Quaternion and Rotation
A unit quaternion has norm 1 and represents a 3D rotation. The 3x3 rotation matrix built from it feeds cleanly into graphics or robotics code.
Use the norm mode to confirm a quaternion is a unit quaternion before passing it to a function that assumes unit length, then switch to the rotation matrix mode to see the equivalent matrix in one click.
The norm of a quaternion is the same square-root-of-sum-of-squares operation that the vector magnitude calculator runs on plain 3D vectors, so the two calculators share the same magnitude formula applied to a different number of components.
How to Use This Calculator
Five quick steps are enough.
- 1 Enter the four components of q1: Type the scalar w1 and the i, j, k coefficients (x1, y1, z1) of the first quaternion. Leave a field at 0 for any component you do not need.
- 2 Enter q2 when needed: For add and multiply modes, also type w2, x2, y2, and z2.
- 3 Pick the operation: Choose multiply for the Hamilton product, add for componentwise addition, conjugate, norm, inverse, or rotation matrix.
- 4 Read the result and, if relevant, the matrix: The result panel shows the four result components. For the rotation matrix mode, the same panel also shows the 3x3 matrix.
- 5 Copy the result into your code or notes: Use the result components as input to another calculator or to your own rotation code. For unit quaternions, the result of multiply then inverse is the identity quaternion.
For a 90 degree rotation about z, the half-angle unit quaternion has w1 = z1 = sqrt(2)/2 (about 0.7071), so enter w1 = 0.7071, x1 = 0, y1 = 0, z1 = 0.7071 and choose rotation matrix. The resulting 3x3 matrix maps the x-axis (1, 0, 0) to the y-axis (0, 1, 0) and the y-axis to (-1, 0, 0).
Benefits of Using This Calculator
A purpose-built calculator saves time and removes the sign errors of doing Hamilton product math by hand.
- • Removes sign errors in the Hamilton product: The Hamilton product has 16 sign-sensitive terms. Doing it by hand is easy to get wrong.
- • Covers every standard operation: Add, multiply, conjugate, norm, inverse, and rotation matrix are all in one tool.
- • Verifies unit quaternions in one click: The norm mode returns |q| directly, so you can confirm a quaternion is a unit quaternion.
- • Outputs a ready-to-use rotation matrix: The rotation matrix mode returns the 3x3 matrix in a clean text block, ready to drop into a graphics shader.
- • Includes a worked example for every common case: The how-it-works section walks through the identity quaternion test and the i*j=k test.
For 2D complex arithmetic, the complex number calculator covers add, subtract, multiply, and divide, while the cartesian to polar calculator is the 2D analog of converting a quaternion to a rotation matrix.
When the rotation matrix mode of this calculator returns a 3x3 matrix, the natural next step is the inverse of that matrix, and the adjoint matrix calculator is the right tool for that step because it handles the matrix inverse using the same adjugate formula.
Factors That Affect Your Results
Three factors decide the result, and three limitations tell you when to double-check.
Component Signs
A flip in the sign of any single component can change a rotation into its mirror image, so the i, j, k signs carry the full geometric meaning of the rotation.
Quaternion Length
Multiplication scales the result by the product of the lengths of the two inputs, so a non-unit quaternion multiplied by another non-unit quaternion produces a result whose length is the product of the two lengths.
Order of Multiplication
The Hamilton product is not commutative, so q1 * q2 and q2 * q1 are usually different. The result panel shows the product in the order the form is filled.
Quaternion Sign Equivalence
A quaternion q and its negation -q represent the same 3D rotation. The calculator returns the literal algebraic result.
- • The calculator uses single-precision floating point math. For high-precision symbolic work, use a dedicated computer algebra system.
- • The rotation matrix mode is intended for unit quaternions. If the input is not unit length, the calculator normalizes it and surfaces a warning.
- • Quaternion addition does not have a clean geometric meaning. Use the Hamilton product to combine two rotations, not the componentwise sum.
The vector magnitude calculator runs the same sqrt(sum of squares) on a 3D vector, and the adjoint matrix calculator inverts a 3x3 rotation matrix.
As published by EuclideanSpace, a unit quaternion converts to a 3x3 rotation matrix with entries from xx, yy, zz, xy, xz, yz, wx, wy, wz in the pattern used in 3D graphics and robotics.
The a+bi representation of a complex number is the 2D analog of the w + xi + yj + zk representation of a quaternion, and the a+bi form calculator covers that 2D form when the problem does not need the extra two imaginary components.
Frequently Asked Questions
Q: How do you multiply two quaternions?
A: Multiply two quaternions by expanding the Hamilton product. The scalar part of the result is w1*w2 - x1*x2 - y1*y2 - z1*z2, and the i, j, k parts come from a mix of products with signs that follow from i^2 = j^2 = k^2 = ijk = -1.
Q: What is a quaternion's conjugate used for?
A: The conjugate of q = w + xi + yj + zk is w - xi - yj - zk. It flips the sign of the vector part, leaves the scalar part unchanged, and is used in the inverse formula and in the rotation formula for unit quaternions.
Q: How do you convert a quaternion to a rotation matrix?
A: For a unit quaternion (w, x, y, z), the 3x3 rotation matrix is built from xx, yy, zz, xy, xz, yz, wx, wy, and wz in a specific symmetric pattern. The diagonal entries are 1 - 2*(yy + zz), 1 - 2*(xx + zz), and 1 - 2*(xx + yy), and the off-diagonal entries pair the remaining terms with the right signs.
Q: What is the norm of a quaternion?
A: The norm of q = w + xi + yj + zk is the square root of w^2 + x^2 + y^2 + z^2. A quaternion is a unit quaternion when its norm equals 1, and only unit quaternions represent 3D rotations in the shortest-arc sense.
Q: How do you find the inverse of a quaternion?
A: The inverse of a non-zero quaternion is the conjugate divided by the squared norm, so q^(-1) = (w - xi - yj - zk) / (w^2 + x^2 + y^2 + z^2). For a unit quaternion the inverse is the same as the conjugate, because the squared norm is 1.
Q: What is the difference between quaternions and complex numbers?
A: A complex number a + bi has one imaginary unit, while a quaternion w + xi + yj + zk has three imaginary units i, j, k with the multiplication rule i^2 = j^2 = k^2 = ijk = -1. Quaternions are the four-dimensional generalization of complex numbers, and they are the natural language for combining 3D rotations without the gimbal lock that affects Euler angles.