Quaternion Calculator

3D rotations & algebra

Work with quaternions for 3D rotations and algebraic operations. Define quaternions, add/subtract, multiply, conjugate, normalize, invert, build rotation quaternions from axis–angle and rotate 3D vectors with an interactive 3D visualization of the original and rotated vector.

quaternion arithmetic 3D rotation axis–angle & unit quaternions graphics & robotics

Quaternion inputs & algebra

Quaternion q₁

Form: q = w + x i + y j + z k

Typical rotation quaternions are unit length: \(\|q\| = 1\).

Quaternion q₂ (optional)

For addition, subtraction or chained rotations.

Use q₂ for composing rotations (q = q₂·q₁, etc.).

Quaternion multiplication is not commutative: q₁·q₂ ≠ q₂·q₁ in general.

Uses q = (cos(θ/2), u·sin(θ/2)).

3D rotation with quaternion & interactive visualisation

Unit quaternion required for pure rotation
Rotation quaternion qrot

You can reuse q₁ above, or type directly.

Vector to rotate v

3D vector v = (vx, vy, vz).

Rotated vector & rotation matrix

Original vector v
Rotated vector v′

Simple orthographic-like projection. Rotate around different axes to see the path from v to v′.

Rotation matrix R (3×3) equivalent to qrot

v′ = R · v

For a unit quaternion q = (w, x, y, z), the matrix R is orthogonal with determinant 1, so it preserves lengths and angles.

What is a quaternion?

A quaternion is a hyper-complex number of the form \[ q = w + x \mathbf{i} + y \mathbf{j} + z \mathbf{k}, \] where \(w, x, y, z \in \mathbb{R}\) and \(\mathbf{i}, \mathbf{j}, \mathbf{k}\) satisfy \(\mathbf{i}^2 = \mathbf{j}^2 = \mathbf{k}^2 = \mathbf{ijk} = -1\). Quaternions extend complex numbers and form a non-commutative division algebra.

Basic quaternion operations

  • Addition: component-wise — \(q_1 + q_2 = (w_1 + w_2,\; x_1 + x_2,\; y_1 + y_2,\; z_1 + z_2)\).
  • Conjugate: \(\overline{q} = (w,\; -x,\; -y,\; -z)\).
  • Norm: \(\|q\| = \sqrt{w^2 + x^2 + y^2 + z^2}\).
  • Inverse: for \(q \neq 0\), \(q^{-1} = \overline{q} / \|q\|^2\).

Multiplication is more involved but encodes rotation when \(\|q\| = 1\).

Quaternions and 3D rotations

A unit quaternion (\(\|q\| = 1\)) can represent a 3D rotation. Given an axis–angle pair (a unit axis \( \mathbf{u} = (u_x,u_y,u_z)\) and angle \(\theta\)):

\[ q = \left(\cos\frac{\theta}{2},\; u_x \sin\frac{\theta}{2},\; u_y \sin\frac{\theta}{2},\; u_z \sin\frac{\theta}{2}\right). \]

To rotate a vector \(\mathbf{v} = (v_x,v_y,v_z)\), embed it as a pure quaternion \(p = (0, v_x, v_y, v_z)\) and compute:

\[ p' = q \, p \, q^{-1}. \] The rotated vector is the imaginary part of \(p'\).

Rotation matrix from quaternion

For a unit quaternion \(q = (w,x,y,z)\), the corresponding \(3\times3\) rotation matrix is

\[ R = \begin{bmatrix} 1 - 2(y^2 + z^2) & 2(xy - wz) & 2(xz + wy) \\ 2(xy + wz) & 1 - 2(x^2 + z^2) & 2(yz - wx) \\ 2(xz - wy) & 2(yz + wx) & 1 - 2(x^2 + y^2) \end{bmatrix}. \]

The calculator uses this matrix internally to show the linear map \( \mathbf{v}' = R\mathbf{v} \) alongside the direct quaternion formula.

Typical applications

  • Game development & graphics: camera orientation, character bones, camera rigs.
  • Robotics & drones: attitude representation, sensor fusion, control loops.
  • Simulation & physics: rigid body orientation and numerical integration of angular velocity.
  • Interpolation: smooth orientation interpolation using slerp between two unit quaternions.

Related algebra & 3D math tools