Saved

Press the star next to a tool's name to save it.

All my tools

Quaternion Calculator

Use this quaternion calculator to add, subtract, multiply and divide quaternions, find the conjugate, norm and inverse, and rotate a vector with a unit quaternion.

Restored your last values ·

A quaternion is a + bi + cj + dk. Enter the four parts of the first quaternion, and of the second for an operation that needs two. For a rotation, enter the axis, the angle and the vector. The calculator shows the answer in the form a + bi + cj + dk.

Everything is worked out in your browser. Nothing you type is sent anywhere.

–

–

Choose what you want, enter the quaternion parts, then press Calculate.

See full result

A quaternion calculator adds, subtracts, multiplies and divides quaternions, finds the conjugate, the norm and the inverse, and uses a quaternion to rotate a vector in 3D. Enter the four parts a, b, c and d of each quaternion a + bi + cj + dk, choose the operation and press the button. The result is shown in the same form. It works in your browser.

How to use the quaternion calculator

  1. Choose the operation.
  2. Enter the parts of the first quaternion, and of the second one if the operation needs it.
  3. For a rotation, enter the axis, the angle in degrees and the vector.
  4. Press Calculate.

What a quaternion is

The Wikipedia article on quaternions writes them as a + bi + cj + dk with a, b, c and d real. The number a is the scalar part and bi + cj + dk is the vector part.[1] The imaginary units follow the rule i² = j² = k² = ijk = −1, which William Hamilton carved on Brougham Bridge. The page shows that i · j = k and j · i = −k, and so quaternion multiplication is not commutative, which means that the result depends on the order of the factors.[1] Addition is done part by part.

The Hamilton product

The article on quaternions and spatial rotation gives the product of (a + bi + cj + dk) and (e + fi + gj + hk) as (ae − bf − cg − dh) + (af + be + ch − dg)i + (ag − bh + ce + df)j + (ah + bg − cf + de)k.[2] For (1 + 2i + 3j + 4k) × (5 + 6i + 7j + 8k), the real part is 5 − 12 − 21 − 32 = −60, the i part is 6 + 10 + 24 − 28 = 12, the j part is 7 − 16 + 15 + 24 = 30 and the k part is 8 + 14 − 18 + 20 = 24. The answer is −60 + 12i + 30j + 24k. In the other order, the answer is −60 + 20i + 14j + 32k, and the calculator shows both, so that you can see the difference.

Conjugate, norm and inverse

The conjugate of q = a + bi + cj + dk is a − bi − cj − dk. The norm is the square root of the product of q and its conjugate, which is √(a² + b² + c² + d²), the usual length in four dimensions.[1] For 1 + 2i + 3j + 4k, the norm is √30, about 5.477. The inverse is the conjugate divided by the square of the norm, q⁻¹ = q* ÷ ‖q‖², which the page writes in the equivalent form (s − v) ÷ (s² + ‖v‖²) for scalar part s and vector part v.[2] Only the zero quaternion has no inverse. To divide p by q, the calculator multiplies p by the inverse of q, in that order, and it also gives the result of multiplying from the left.

Rotating a vector

The page on spatial rotation says that a unit quaternion q = cos(θ ÷ 2) + u sin(θ ÷ 2), with u a unit axis vector, rotates a vector p by the conjugation p ↦ q p q⁻¹, with p written as the quaternion (0, p).[2] Rotating by q = (1 + k) ÷ √2, that is 90 degrees about the z-axis, turns the vector (1, 0, 0) into (0, 1, 0). The page also notes that q and −q give the same rotation, and that composing rotations is multiplication, in which q₂q₁ means the rotation q₁ followed by q₂, with the order mattering.[2] The calculator normalizes your axis, builds the quaternion and rotates your vector.

A rotation example from the article

The article's worked example is a rotation of 120 degrees about the axis i + j + k. Its quaternion is (1 + i + j + k) ÷ 2, and it carries ai + bj + ck to ci + aj + bk, which cyclically permutes the axes.[2] Enter the axis (1, 1, 1), the angle 120 and the vector (1, 2, 3), and the calculator returns (3, 1, 2), which is the same permutation. You can use the quaternion shown in the result in 3D graphics code, where quaternions are popular because they avoid some problems of rotation angles and combine easily.

Why quaternions are used

Quaternions represent a rotation with four numbers, without the gimbal lock that can affect three rotation angles, and the product of two rotations is a single quaternion multiplication. This is why they are used in computer graphics, robotics, aerospace and games. The calculator is a convenient way to check a hand calculation or to try out numbers before putting them in code.

Quaternions and complex numbers

Quaternions extend complex numbers. If you keep only the real part and one imaginary unit, such as a + bi, the rules reduce to ordinary complex arithmetic, in which multiplication is commutative. The extra units j and k are what make rotations in three dimensions possible, and they are also what makes the product depend on the order. Hamilton found the rules in 1843, and quaternions remain a standard tool whenever a program has to turn an object smoothly or combine several turns without error.

Common mistakes

  • Multiplying in the wrong order. p × q and q × p differ.
  • Using a non-unit quaternion for a rotation. Build it from the axis and angle, which normalizes it.
  • Halving the angle twice. The quaternion uses θ ÷ 2, and the calculator does that for you.
  • Dividing by zero. The zero quaternion has no inverse.

What next

Use this often? Add Quaternion to your Home screen.

Frequently asked questions

What is a quaternion calculator?

A tool that does arithmetic with quaternions, numbers of the form a + bi + cj + dk, and uses them to rotate vectors in 3D.

Why is quaternion multiplication not commutative?

Because ij = k but ji = −k. The order of the factors changes the result.

How do I find the inverse of a quaternion?

Divide its conjugate by the square of its norm. For 1 + 2i + 3j + 4k, the inverse is (1 − 2i − 3j − 4k) ÷ 30.

How does a quaternion rotate a vector?

With the unit quaternion q = cos(θ ÷ 2) + u sin(θ ÷ 2), the vector p is rotated to q p q⁻¹.

What is the norm of a quaternion?

The square root of a² + b² + c² + d². It is the length of the quaternion as a point in four dimensions.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Math Tools