Standalone interactive tutorial

Four numbers.
One smooth turn.

Quaternions extend complex numbers into four dimensions. Unit quaternions provide a compact, stable way to represent and combine rotations in three-dimensional space.

This is one self-contained HTML file. All styling and calculations are embedded as CSS and plain JavaScript. It needs no installation, web server, framework, or internet connection. Use your browser's Print command to save a PDF.

q = w + xi + yj + zk    i² = j² = k² = ijk = −1
Scalar-first · Hamilton product · active right-handed rotations
Live rotation lab

Turn the x-vector

q normalized
original v=(1,0,0) · rotated v′ · axis û
History

From triplets to a four-dimensional algebra

Before 1843

The 3-D multiplication problem

Complex numbers gave mathematicians an algebra for planar rotations. William Rowan Hamilton spent years trying to find an analogous multiplication for ordered triples, but three components were not sufficient.

16 Oct. 1843

The bridge insight

Hamilton realized that the system required one real component and three imaginary components. He later wrote that he cut the defining formula into a stone at Brougham—now Broome—Bridge in Dublin.

1843–1853

Formal development

Hamilton presented the discovery to the Royal Irish Academy on 13 November 1843 and published his 736-page Lectures on Quaternions in 1853.

20th century onward

The rotation specialist

Quaternions became central to inertial navigation, spacecraft attitude, robotics, computer graphics, animation, games, and sensor fusion.

First intuition

A scalar plus a 3-D direction

Think of q=(w,x,y,z) as a four-number package. The first number is scalar. The final three act like a vector. When the package has length one, it can encode a pure 3-D rotation.

Scalar part: w

w = cos(θ/2)

It is tied to the rotation angle, but it is not the angle itself. For a small turn, w is close to one.

Vector part: (x,y,z)

(x,y,z) = û sin(θ/2)

Its direction is the rotation axis. Its length stores the sine of half the angle.

q = cos(θ/2) + (uₓi + uᵧj + u𝓏k) sin(θ/2)
  1. Choose a turn. Rotate 90° about z: û=(0,0,1).
  2. Halve the angle. θ/2=45°.
  3. Fill the slots. q=(0.7071,0,0,0.7071).
  4. Apply it. q(0,1,0,0)q⁻¹=(0,0,1,0), so x becomes y.
The half-angle is essential. Unit quaternions live on the 3-sphere S³, and q and −q encode the same physical orientation. This makes S³ a double cover of the 3-D rotation group SO(3).
Algebraic perspective

What a quaternion is

Simplified view

A quaternion is a package of four real numbers. Write q=(w,x,y,z). The first number is the scalar part. The last three form the vector part. A unit quaternion can encode a 3-D rotation.

Rigorous view

ℍ is a four-dimensional associative division algebra over ℝ with basis 1,i,j,k. It is noncommutative: ij=k but ji=−k. Every nonzero quaternion has a multiplicative inverse.

Hamilton product

For q=(a,u) and r=(b,v):
qr=(ab−u·v, av+bu+u×v)

The scalar term contains a dot product; the vector term contains a cross product. Reversing the order reverses that cross-product term.

Basis multiplication

×ijk
i−1k−j
j−k−1i
kj−i−1

Conjugate

q̄=(w,−x,−y,−z)

Reverses the vector part.

Norm

‖q‖=√(w²+x²+y²+z²)

Multiplicative: ‖qr‖=‖q‖‖r‖.

Inverse

q⁻¹=q̄/‖q‖²

For a unit quaternion, q⁻¹=q̄.

Composition

R(q₂q₁)=R(q₂)R(q₁)

q₁ acts first under this page's convention.

Conventions differ. Some software uses [x,y,z,w], passive rotations, left-handed frames, or the JPL multiplication convention. Always document component order, frame direction, handedness, and multiplication signs.
Geometric perspective

Axis, angle, and the unit 3-sphere

1. Choose a turn

Select unit axis û and right-handed angle θ.

2. Encode it

q=(cos(θ/2), û sin(θ/2))

Its norm is one, so q lies on S³.

3. Rotate a vector

p′=qpq⁻¹, where p=(0,v)

The vector part of p′ is the rotated vector.

Why q and −q are the same turn

(−q)p(−q)⁻¹=qpq⁻¹

The signs cancel. Unit quaternions form Spin(3), a double cover of SO(3): every physical orientation corresponds to two antipodal points on S³.

Why the sandwich works

Expand qpq⁻¹ and the result is Rodrigues' formula:

v′=v cosθ+(û×v)sinθ+û(û·v)(1−cosθ)

The component parallel to the axis stays fixed; the perpendicular component turns through θ.

SLERP: smooth interpolation

Spherical linear interpolation follows a great-circle path on S³ at constant angular speed.

slerp(q₀,q₁;t)=[sin((1−t)Ω)/sinΩ]q₀+[sin(tΩ)/sinΩ]q₁

If q₀·q₁<0, implementations usually negate one endpoint to select the shorter equivalent path.

“No gimbal lock” precisely

Euler angles lose a coordinate degree of freedom when two axes align. Unit-quaternion orientation has no such singularity. Physical gimbals can still lock, and converting back to Euler angles still encounters the Euler-coordinate singularity.

Quaternion vs. vector

Related components, different jobs

Property3-D vectorQuaternion
Components(x,y,z)(w,x,y,z)
Main meaningDirection and magnitude: position, velocity, force, or axisA member of ℍ; when unit length, a 3-D orientation
ProductsDot product gives a scalar; cross product gives a vectorHamilton product gives another quaternion and includes both dot and cross products
Rotation roleThe object being rotated or the rotation axisThe operator that rotates the vector via q(0,v)q⁻¹
OrderAddition commutes; cross product changes sign when reversedqr generally differs from rq
InterpolationLinear interpolation is commonNormalized lerp or SLERP is used for orientation
Offline calculator suite

Calculate and convert

All calculator results update when you press the associated button. Decimal input is accepted. Rotation tools normalize the quaternion automatically.

Quaternion arithmetic

Enter q = (w,x,y,z) and r = (w,x,y,z).

q

r

q × r = 1 + 1i + 1j + 1k

Axis–angle ↔ quaternion

Axes and quaternions are normalized automatically.

Encode an axis and angle

q = 0.707107 + 0i + 0j + 0.707107k

Decode a quaternion

Press Decode rotation.

Rotate a vector

Computes q(0,v)q⁻¹.

q

v

v′ = (0, 1, 0)

Euler attitude ↔ quaternion

Uses aerospace-style active Rz(yaw)Ry(pitch)Rx(roll), column vectors.

Press Convert attitude.
Applications

Where quaternions earn their keep

Aerospace & spacecraft

Attitude determination, inertial navigation, star-tracker filtering, guidance, control, and coordinate-frame transformations.

Robotics

End-effector orientation, pose estimation, inverse kinematics, motion planning, and sensor fusion.

Graphics & animation

Camera orientation, skeletal joints, keyframe interpolation, virtual reality, and game-engine transforms.

Computer vision

Camera pose, bundle adjustment, simultaneous localization and mapping, and 3-D reconstruction.

Choose representations by task. Matrices are often clearest for transforming many vectors; Euler angles are intuitive for reporting attitude; quaternions are compact and strong at composition and interpolation. Engineers routinely convert among all three.
References

Continue learning