Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random | Template Test |  
Login
create new user
Username:
Password:
forget your password?
Main Menu
Sections

Meta

Talkback

Downloads

Information
quaternions and Euler angles (Topic)

Quaternions and Euler Angles

Euler angles and quaternions are two of the most common ways to describe three-dimensional orientation. Euler angles are intuitive because they express an orientation as a sequence of familiar one-axis rotations such as yaw, pitch, and roll. Quaternions are more compact for computation and avoid the singularities that arise in Euler angle coordinates. This entry shows how the standard 3-2-1 yaw-pitch-roll sequence is related to a unit quaternion and how one converts in both directions.

Convention declaration

This article uses the PhysicsLibrary house convention:

  1. right-handed orthonormal frames;
  2. Hamilton multiplication, so $\mathbf i\mathbf j=\mathbf k$;
  3. scalar-first display notation,
    $\displaystyle q=q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k;$ (1)
  4. active vector rotation,
    $\displaystyle \mathbf v' = q\mathbf v q^* = R(q)\mathbf v.$ (2)

The specific Euler angle convention treated here is the
3-2-1 yaw-pitch-roll sequence. In matrix form we define

$\displaystyle \boxed{R = R_z(\psi)R_y(\theta)R_x(\phi),}$ (3)
where
$\displaystyle \psi =$   yaw$\displaystyle , \qquad \theta =$   pitch$\displaystyle , \qquad \phi =$   roll$\displaystyle .$ (4)
The same orientation may be described either as successive active rotations or, in an equivalent geometric language, as a moving axis sequence. The safest practice is always to declare the explicit matrix or quaternion product.

Euler angle families

There are two broad families of Euler angle sequences.

  1. Proper Euler angle sequences reuse one axis, for example 3-1-3.
  2. Tait-Bryan sequences use three distinct axes, for example 3-2-1.
The yaw-pitch-roll convention of engineering and aerospace work is a Tait-Bryan sequence.

Elementary axis quaternions

A rotation of angle $\alpha$ about the positive $x$ axis is represented by

$\displaystyle q_x(\alpha)=\cos\frac{\alpha}{2}+\mathbf i\sin\frac{\alpha}{2}.$ (5)
Similarly,
$\displaystyle q_y(\beta)=\cos\frac{\beta}{2}+\mathbf j\sin\frac{\beta}{2}, \qquad q_z(\gamma)=\cos\frac{\gamma}{2}+\mathbf k\sin\frac{\gamma}{2}.$ (6)
Therefore the unit quaternion corresponding to the 3-2-1 sequence is
$\displaystyle \boxed{q = q_z(\psi)q_y(\theta)q_x(\phi).}$ (7)
This product order matches the active composition rule of Q08: the roll acts first, then the pitch, and then the yaw in the written matrix product $R_z(\psi)R_y(\theta)R_x(\phi)$.

Step-by-step geometry

Figure [*] illustrates the stepwise 3-2-1 sequence. The yaw, pitch, and roll arcs are shown in different colors to distinguish the three elementary rotations.

Figure: The 3-2-1 yaw-pitch-roll sequence. Step 1 rotates about the reference $z$ axis by the yaw angle $\psi$. Step 2 rotates about the intermediate $y_1$ axis by the pitch angle $\theta$. Step 3 rotates about the intermediate $x_2$ axis by the roll angle $\phi$. For the active convention used here, the net matrix and quaternion are $R=R_z(\psi)R_y(\theta)R_x(\phi)$ and $q=q_z(\psi)q_y(\theta)q_x(\phi)$.
Image Q10_euler_sequence

Quaternion formula for the 3-2-1 sequence

Introduce the half-angle abbreviations

$\displaystyle c_\phi = \cos\frac{\phi}{2}, \qquad s_\phi = \sin\frac{\phi}{2},$ (8)
$\displaystyle c_\theta = \cos\frac{\theta}{2}, \qquad s_\theta = \sin\frac{\theta}{2},$ (9)
$\displaystyle c_\psi = \cos\frac{\psi}{2}, \qquad s_\psi = \sin\frac{\psi}{2}.$ (10)
Then
$\displaystyle q_x(\phi)=c_\phi + \mathbf i s_\phi, \qquad q_y(\theta)=c_\theta + \mathbf j s_\theta, \qquad q_z(\psi)=c_\psi + \mathbf k s_\psi.$ (11)
Multiplying the three factors gives
$\displaystyle \boxed{ q = q_w + q_x\mathbf i + q_y\mathbf j + q_z\mathbf k, }$ (12)
with components
$\displaystyle \boxed{ q_w = c_\phi c_\theta c_\psi + s_\phi s_\theta s_\psi, }$ (13)
$\displaystyle \boxed{ q_x = s_\phi c_\theta c_\psi - c_\phi s_\theta s_\psi, }$ (14)
$\displaystyle \boxed{ q_y = c_\phi s_\theta c_\psi + s_\phi c_\theta s_\psi, }$ (15)
$\displaystyle \boxed{ q_z = c_\phi c_\theta s_\psi - s_\phi s_\theta c_\psi. }$ (16)
These are among the most frequently used formulas in navigation, flight-dynamics, robotics, and graphics software.

The associated 3-2-1 rotation matrix

The same sequence has matrix form

$\displaystyle \boxed{ R = \begin{bmatrix} c_\psi c_\theta & c_\psi s_\theta s_\... ...c_\psi s_\phi\ -s_\theta & c_\theta s_\phi & c_\theta c_\phi \end{bmatrix}. }$ (17)
Equating this matrix with the quaternion-generated matrix of Q09 provides a useful cross-check of the component formulas in equations (13) through (16).

Recovering yaw, pitch, and roll from a quaternion

Starting from either equation (17) or the component formulas of Q09, one may recover the 3-2-1 angles by

$\displaystyle \boxed{ \phi = \operatorname{atan2}\!\left(2(q_w q_x + q_y q_z),\ 1-2(q_x^2+q_y^2)\right), }$ (18)
$\displaystyle \boxed{ \theta = \arcsin\!\left(2(q_w q_y - q_z q_x)\right), }$ (19)
$\displaystyle \boxed{ \psi = \operatorname{atan2}\!\left(2(q_w q_z + q_x q_y),\ 1-2(q_y^2+q_z^2)\right). }$ (20)
These formulas assume the same 3-2-1 convention and the same active/Hamilton sign conventions used above.

Singularity and gimbal lock

Euler angles are local coordinates on the orientation manifold, not a global one-to-one description. In the 3-2-1 sequence the singularity occurs when

$\displaystyle \boxed{\theta = \pm \frac{\pi}{2}.}$ (21)
At this pitch angle the yaw and roll axes align, and the decomposition loses one degree of freedom. In engineering language this is called gimbal lock. Quaternions do not suffer from this coordinate singularity, which is one of the main reasons they are preferred for simulation, estimation, and control.

A simple example

Consider pure yaw with

$\displaystyle \phi = 0, \qquad \theta = 0, \qquad \psi = \frac{\pi}{2}.$ (22)
Then equations (13) through (16) reduce to
$\displaystyle q_w = \cos\frac{\pi}{4} = \frac{1}{\sqrt2}, \qquad q_z = \sin\frac{\pi}{4} = \frac{1}{\sqrt2},$ (23)
with $q_x=q_y=0$. Therefore
$\displaystyle q = \frac{1+\mathbf k}{\sqrt2},$ (24)
which is exactly the quarter-turn about the axis discussed previously.

Common pitfalls

The most common mistakes are:

  1. mixing a scalar-first quaternion formula with scalar-last stored data;
  2. using formulas from a source that assumes a different sequence, such as 1-2-3 instead of 3-2-1;
  3. confusing active and passive interpretations;
  4. forgetting that intrinsic and extrinsic descriptions may refer to the same final orientation but use different verbal descriptions;
  5. treating Euler angle formulas as globally valid even at or near the singularity $\theta=\pm\pi/2$.

What comes next

The next entry develops quaternion kinematics and the differential equation that propagates attitude from angular velocity.

Sources and historical notes

The formulas in this entry are standard in navigation and rigid-body dynamics. The main conceptual difficulty is usually not the algebra but the coexistence of multiple sign, order, and sequence conventions. That is why PhysicsLibrary states the convention explicitly before giving any conversion formulas.

License

This article is an original synthesis prepared for PhysicsLibrary and intended for release under CC BY-SA 4.0.



"quaternions and Euler angles" is owned by bloftin.
(view preamble)
View style:
Keywords:  quaternion, Euler angles, yaw pitch roll, 321 sequence, Tait-Bryan angles, gimbal lock, attitude parameterization

Attachments:
example of quaternions and Euler angles (Example) by bloftin

Cross-references: velocity, differential equation, kinematics, manifold, formulas, matrix product, composition, work, Euler angle sequences, quaternion product, matrix, vector, computation, quaternions
There is 1 reference to this object.

This is version 2 of quaternions and Euler angles, born on 2026-08-24, modified 2026-08-24.
Object id is 1103, canonical name is QuaternionsAndEulerAngles.
Accessed 11 times total.

Classification:
Physics Classification02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)
 45.40.-f (Dynamics and kinematics of rigid bodies)
Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:

No messages.

Interact
rate | post | correct | update request | add example | add (any)