Report

Help us improve this tool

Quaternion Calculator

Perform quaternion addition, subtraction, Hamilton multiplication, division, norm, inverse, and 3D vector rotation online.

O M T

Understanding Quaternions

Quaternions are a four-dimensional number system that extends the classical two-dimensional complex numbers. First discovered in 1843 by Irish mathematician Sir William Rowan Hamilton, quaternions provide an elegant, singularity-free algebraic framework for computing three-dimensional spatial orientations and rotations in robotics, 3D computer graphics, aerospace navigation, physics, and computer vision.

A quaternion $q$ is expressed in hypercomplex form with one real scalar part $w$ and three orthogonal imaginary vector parts $x, y, z$:

$$q = w + xi + yj + zk$$

Where $w, x, y, z \in \mathbb{R}$, and the imaginary unit elements $i, j, k$ obey Hamilton's fundamental non-commutative relations:

$$i^2 = j^2 = k^2 = ijk = -1$$

From these defining equations follow the cyclic multiplication rules:

$$ij = k, \quad jk = i, \quad ki = j$$ $$ji = -k, \quad kj = -i, \quad ik = -j$$

Quaternion Arithmetic Operations

Addition and Subtraction

Quaternion addition and subtraction are performed component-wise, analogous to 4D vector arithmetic:

$$q_1 \pm q_2 = (w_1 \pm w_2) + (x_1 \pm x_2)i + (y_1 \pm y_2)j + (z_1 \pm z_2)k$$

Hamilton Product (Multiplication)

Multiplication of two quaternions is associative and distributive, but strictly non-commutative ($q_1 q_2 \neq q_2 q_1$). Expanding the terms according to Hamilton's rules yields:

$$w = w_1 w_2 - x_1 x_2 - y_1 y_2 - z_1 z_2$$ $$x = w_1 x_2 + x_1 w_2 + y_1 z_2 - z_1 y_2$$ $$y = w_1 y_2 - x_1 z_2 + y_1 w_2 + z_1 x_2$$ $$z = w_1 z_2 + x_1 y_2 - y_1 x_2 + z_1 w_2$$

Norm, Conjugate, and Multiplicative Inverse

The conjugate of a quaternion $q^*$ reverses the sign of its imaginary vector components:

$$q^* = w - xi - yj - zk$$

The norm (or Euclidean magnitude) $|q|$ is the square root of the scalar product of $q$ with its conjugate:

$$|q|^2 = q q^* = w^2 + x^2 + y^2 + z^2, \quad |q| = \sqrt{w^2 + x^2 + y^2 + z^2}$$

For any non-zero quaternion, the multiplicative inverse $q^{-1}$ satisfies $q q^{-1} = q^{-1} q = 1$ and is calculated as:

$$q^{-1} = \frac{q^*}{|q|^2}$$

Quaternion division $q_1 / q_2$ is defined by multiplying $q_1$ by the inverse of $q_2$: $q_1 \cdot q_2^{-1}$.

3D Spatial Rotations and Gimbal Lock Prevention

In 3D computer graphics, flight dynamics, and game engines (such as Unity and Unreal Engine), unit quaternions ($|q| = 1$, also known as versors) represent spatial rotations without the risk of gimbal lock encountered when using Euler angles (pitch, roll, and yaw).

To rotate a vector $\vec{v} = (v_x, v_y, v_z)$ by an angle $\theta$ around a unit axis $\vec{u} = (u_x, u_y, u_z)$, construct the unit quaternion:

$$q = \cos\left(\frac{\theta}{2}\right) + \vec{u} \sin\left(\frac{\theta}{2}\right)$$

The rotated vector $\vec{v}'$ is obtained by treating $\vec{v}$ as a pure quaternion $p = 0 + v_x i + v_y j + v_z k$ and evaluating the triple product:

$$p' = q \cdot p \cdot q^{-1} = q \cdot p \cdot q^*$$

Explore related mathematical utilities on OnlineMiniTools, including the Complex Calculator, Matrix Multiply Calculator, Matrix Inverse Calculator, and the Random Vector Generator.

Frequently Asked Questions

Why is quaternion multiplication non-commutative?

Quaternion multiplication does not commute ($q_1 q_2 \neq q_2 q_1$) because its imaginary units satisfy anticommutative relations: $ij = k$ while $ji = -k$. Geometrically, this directly reflects the fact that 3D rotations are non-commutative; rotating an object 90 degrees about the X-axis and then 90 degrees about the Y-axis produces a completely different orientation than performing those rotations in reverse order.

What is a unit quaternion and why is it used for 3D rotations?

A unit quaternion (or versor) is a quaternion whose Euclidean norm $|q| = \sqrt{w^2 + x^2 + y^2 + z^2}$ is exactly 1. Unit quaternions represent pure rotations in three-dimensional space. Unlike Euler angles, unit quaternions never suffer from gimbal lock (loss of one rotational degree of freedom), interpolate smoothly via Spherical Linear Interpolation (SLERP), and require significantly less memory than full 3x3 rotation matrices.

How do you compute the inverse of a quaternion?

The inverse $q^{-1}$ of a non-zero quaternion is computed by taking its conjugate $q^* = w - xi - yj - zk$ and dividing every component by the squared norm $|q|^2 = w^2 + x^2 + y^2 + z^2$. If the quaternion is already normalized (a unit quaternion where $|q| = 1$), the inverse is simply identical to its conjugate ($q^{-1} = q^*$).

What is the difference between a quaternion and a 4D vector?

While a quaternion consists of four real numbers like a 4-vector, quaternions possess a well-defined associative division algebra with the Hamilton product. This enables quaternions to encode spatial rotations, compose successive orientations through multiplication, and perform division, operations that do not exist in standard 4D vector spaces.

What does the scalar part w represent in a rotation quaternion?

In a rotation unit quaternion, the scalar component is $w = \cos(\theta / 2)$, where $\theta$ is the angle of rotation. The vector components $(x, y, z)$ are equal to $\vec{u} \sin(\theta / 2)$, where $\vec{u}$ is the unit axis of rotation. The half-angle parameterization allows double-cover representation of the 3D rotation group SO(3).