Quaternion Attitude

Simulation
Introduced by
William Hamilton (quaternions), aerospace engineers
Year
1843
Type
Mathematical framework
Family
Representation

What does it do?

Quaternion attitude representation describes three-dimensional rotations with four-component vectors (quaternions).

A unit quaternion has no gimbal-lock singularity of the kind that affects Euler angles, so attitude can be propagated continuously through any orientation. Its kinematic equation, dq/dt = ½ q ⊗ ω, relates the rate of change of the quaternion to the body-frame angular velocity measured by gyroscopes.

The intuition behind the method

A quaternion is a four-element vector q = [q0, q1, q2, q3] (equivalently [q_scalar, q_vector]) that encodes a rotation through an angle about an axis. Euler angles (roll, pitch, yaw) describe the same orientations with three numbers, but their parametrisation becomes singular at certain angles, such as pitch of ±90°. The quaternion parametrisation has no such point, so an orientation estimate can be updated step by step without a change of representation. Multiplying two quaternions composes the corresponding rotations, although the order of the factors matters.

History

William Hamilton introduced quaternions in 1843 as an extension of complex numbers. Their use for describing rotations in engineering is developed in the inertial navigation literature. Titterton and Weston (2004) cover strapdown inertial navigation, in which the attitude is propagated from gyroscope measurements, and Savage's two-part treatment of strapdown attitude algorithms develops quaternion forms for attitude updating. Shuster (1993) surveys the attitude representations used in this field.

When to use it

Choose quaternion representation when attitude must be tracked continuously over arbitrary orientations, for example when integrating gyroscope rates or when attitude is a state in an estimator. It is a natural fit for real-time propagation in inertial navigation and attitude determination, where the sign of the quaternion must be tracked as well. Do not use Euler angles directly in a propagation loop that may pass near gimbal lock. Simple problems involving rotation about a single fixed axis, or problems where the only output is read by a person, may not justify the extra abstraction; in the latter case, convert to Euler angles at the output stage.

Limitations and considerations

  • Double cover: q and -q represent the same rotation, so the sign of the quaternion must be tracked to avoid discontinuities in the estimate.
  • Abstract form: a quaternion does not map directly onto an intuitive picture of roll, pitch and yaw, so engineers usually convert to Euler angles to inspect results.
  • Norm drift: when the kinematic equation is integrated numerically, the quaternion norm departs from one over time, and it must be restored at regular intervals.
  • Ill-conditioned axis extraction: when the rotation angle is close to zero, the rotation axis recovered from the quaternion's vector part is poorly defined, because the axis is divided by a quantity that vanishes.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Continuous parametrisation: a unit quaternion has no gimbal-lock singularity, so the attitude can be propagated through any orientation without switching representations.
  • Compact form: four components are needed, compared with nine entries in a rotation matrix, which keeps storage and propagation simple.
  • Normalisation is a single constraint: the unit-norm condition can be enforced by rescaling a four-component vector, rather than by re-orthogonalising a 3x3 matrix.
  • Smooth interpolation: spherical linear interpolation (SLERP) produces a smooth path between two orientations.

Applications

  • Spacecraft attitude determination: representing satellite orientation without the singularities of Euler angles.
  • Aircraft and spacecraft attitude control: quaternion attitude states can be used directly in control laws.
  • Inertial measurement unit (IMU) processing: integration of gyroscope measurements into an attitude estimate.
  • 3D computer graphics and animation: representing and interpolating rotations between orientations.
  • Robotics and autonomous vehicles: tracking orientation for navigation and motion planning.

How it works

How it works

1

Represent attitude as q = [q0, q1, q2, q3], with q0 the scalar part and [q1, q2, q3] the vector part, normalised so that q0² + q1² + q2² + q3² = 1.

2

Renormalise the quaternion if numerical error has moved its norm away from one. Convert to a rotation matrix or Euler angles only where a display or an interface requires them.

3

Propagate the quaternion with dq/dt = ½ q ⊗ ω, where ω is the body-frame angular velocity measured by the gyroscopes, written as the pure quaternion [0, ω_x, ω_y, ω_z], and q is taken as the body-to-reference rotation (Hamilton convention). The frame of ω must match the convention used to define q; with the opposite convention, the sign and multiplication order of the equation change. The equation is integrated numerically over each time step.

Formula
\dot{\vec{q}} = \frac{1}{2}\vec{q} \otimes \vec{\omega}
4

Update the quaternion with each new gyroscope measurement. Over a step of duration Δt, integrate the gyroscope angular rates into a rotation increment Δθ, form the increment quaternion Δq = [cos(|Δθ|/2), sin(|Δθ|/2)·Δθ/|Δθ|], and update q(k+1) = q(k) ⊗ Δq. This assumes the rotation within the step is small enough that the angular rate can be treated as approximately constant. Rotation about two axes with a phase difference (coning motion) produces an error that a first-order increment does not capture, so a coning correction is required; Savage's two-speed attitude algorithms provide one such compensation. When other sensors are fused, a filter such as a Kalman or complementary filter corrects the propagated attitude.

5

Convert to Euler angles for display, but keep the quaternion for control laws and dynamics. Express attitude uncertainty as the covariance of a three-parameter small-angle error state, defined as a rotation-vector error about the current estimate, and report it alongside the attitude value rather than deriving it from the quaternion itself.

Common pitfalls

  • Forgetting to normalise the quaternion: numerical drift accumulates into attitude error, so periodic normalisation is required.
  • Incorrect multiplication order: q1 ⊗ q2 is not equal to q2 ⊗ q1, so reversing the order of a composition gives a different rotation.
  • Confusing the conjugate with the inverse: for a unit quaternion the inverse equals the conjugate, but this does not hold for quaternions whose norm is not one.
  • Ignoring the double cover in filtering: if the filter does not track sign, the estimate can jump between q and -q, so the quaternion path must be kept continuous.

Frequently asked questions

What is the difference between a quaternion and a rotation matrix?

A quaternion q = [q0, q1, q2, q3] has four components, while a rotation matrix R is a 3x3 orthogonal matrix with nine entries. Both can represent the same rotation, and conversion between them is straightforward. Quaternions are more compact, and products of unit quaternions are often simpler to implement than matrix products, but the choice depends on the implementation and the operations required.

Why do q and -q represent the same rotation?

A unit quaternion q = [cos(θ/2), sin(θ/2) * n] represents rotation by angle θ about axis n. The quaternion -q = [-cos(θ/2), -sin(θ/2) * n] represents the same rotation, since both produce the same rotation matrix. This double cover is handled in filtering by maintaining continuity and avoiding sign flips.

How do I integrate quaternion kinematics?

Use dq/dt = 0.5 * q ⊗ ω, where ω is the body-frame angular velocity, and confirm that its frame matches the convention used to define q (the body-frame form is the usual one for gyroscope measurements). Integrate numerically with Euler, RK4 or another integrator. Renormalise the quaternion after each step so that ||q|| = 1. Exponential-map integration is an alternative: it applies an analytically exact attitude update under the assumption that the angular rate is approximately constant within each step, which can reduce discretisation error. The benefit depends on how the angular rate varies within the step.

How do I convert a quaternion to Euler angles?

Euler angles (roll φ, pitch θ, yaw ψ) computed from q = [q0, q1, q2, q3] involve arctangent functions, and the formulas depend on the angle convention (ZYX, XYZ and others). Gimbal-lock singularities occur at θ = ±90°, and the conversion becomes unreliable near them. Near these angles, keep the quaternion for control rather than the Euler angles.

Related methods

Sources

  1. Shuster, M. D. (1993). A survey of attitude representations. Journal of the Astronautical Sciences, 41(4), 439–517.

    Open publication reference
  2. Titterton, D. H., & Weston, J. L. (2004). Strapdown Inertial Navigation Technology (2nd ed.). Institution of Engineering and Technology.

    Open DOI reference
  3. Savage, P. G. (2000). Strapdown inertial navigation integration algorithm design. Part 1: Attitude algorithms. Journal of Guidance, Control, and Dynamics, 21(1), 19–28.

    Open DOI reference