Works on this device
Quaternion Calculator
Work with quaternions as numbers and as rotations in 3D. Choose what you want to work out, type the four parts w, x, y, z, and read the answer with its working. The convention that the page uses is written with every result.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Calculate.
Your result
How it was worked out
How to use this calculator
- Choose what you want to work out, for example Multiply two quaternions or Quaternion to Euler angles.
- Type each quaternion as four numbers with commas or spaces between them, in the order w, x, y, z:
1, 2, 3, 4. You can also type1 + 2i + 3j + 4k. - If your numbers have the scalar part last (x, y, z, w), open More options and change the order of the four numbers.
- Choose Calculate. You can copy the result or download it as a CSV file.
The convention that this page uses
- A quaternion is q = w + xi + yj + zk. The number w is the scalar part, and (x, y, z) is the vector part.
- The product is the Hamilton product: i² = j² = k² = ijk = −1, so ij = k, jk = i and ki = j. The order matters: p q is usually not q p.
- The frame is right-handed. A unit quaternion turns a vector v into q v q*, where q* is the conjugate. A positive angle is counter-clockwise when you look from the tip of the axis toward the origin.
- For a turn by the angle θ about the unit axis (a, b, c): w = cos(θ ÷ 2) and (x, y, z) = sin(θ ÷ 2) × (a, b, c).
- The rotation matrix R turns a column vector: v′ = R v.
- Euler angles are three rotations, one after the other, each about an axis of the frame that the rotations before it have already turned. You choose the order of the axes. The default is z, then y, then x: yaw, pitch and roll.
- Other fields use other conventions: a scalar part stored last, a product with ij = −k, or a matrix that changes the frame and not the vector. Check which one your source uses before you copy numbers.
The formulas
- Product: (p₀q₀ − p₁q₁ − p₂q₂ − p₃q₃) + (p₀q₁ + p₁q₀ + p₂q₃ − p₃q₂)i + (p₀q₂ − p₁q₃ + p₂q₀ + p₃q₁)j + (p₀q₃ + p₁q₂ − p₂q₁ + p₃q₀)k.
- Conjugate: q* = w − xi − yj − zk. Norm: |q| = √(w² + x² + y² + z²). Inverse: q* ÷ |q|².
- Axis and angle: angle = 2 × atan2(√(x² + y² + z²), w), and the axis is (x, y, z) divided by its length.
- Rotation matrix: row 1 is 1 − 2(y² + z²), 2(xy − wz), 2(xz + wy). Row 2 is 2(xy + wz), 1 − 2(x² + z²), 2(yz − wx). Row 3 is 2(xz − wy), 2(yz + wx), 1 − 2(x² + y²).
- Slerp: q(t) = (sin((1 − t)θ) × q₀ + sin(tθ) × q₁) ÷ sin θ, where cos θ is the dot product of the two unit quaternions.
Worked example
Take p = 1 + 2i + 3j + 4k and q = 2 − i + k. The product p q is 6i + 12k: the scalar part is 1 × 2 − 2 × (−1) − 3 × 0 − 4 × 1 = 0, and the i part is 1 × (−1) + 2 × 2 + 3 × 1 − 4 × 0 = 6. The other order gives q p = 12j + 6k, so the two do not commute. The norm of p is √30.
The quaternion 1 + k has the length √2. Divided by its length, it is a turn by 90° about the z-axis. It turns the vector (1, 0, 0) into (0, 1, 0), and its Euler angles in the order z, y, x are a yaw of 90°, a pitch of 0° and a roll of 0°.
Limits you should know
- Sums, products, conjugates, inverses, rotated vectors and rotation matrices are exact when you type whole numbers, fractions or decimals. Angles, Euler angles and interpolation use ordinary decimal arithmetic and are rounded for display.
- Only a quaternion with the length 1 stands for a rotation. For a rotation result, a quaternion with another length is divided by its length first, and the page says so.
- A quaternion and its opposite (all four signs changed) stand for the same rotation. When the page makes a quaternion from angles or from a matrix, it gives the one with w from 0 up.
- Gimbal lock: when the second Euler angle is 90° or −90°, the first and third rotations turn about the same line, and only their sum or difference is fixed. The page then gives the third angle as 0 and says so.
- The page offers the six orders with three different axes (such as z, y, x). Orders that use one axis twice (such as z, x, z) are not offered.
- A typed rotation matrix must have rows of length 1 at right angles to each other, to within 0.000001.
- This page is a study aid. Check important results, such as the attitude of a vehicle or a robot, against the convention of your own software.