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
[parent] example of quaternions and Euler angles (Example)

Quaternions and Euler Angles: Examples, Exercises, and Solutions

This companion article belongs to the PhysicsLibrary entry quaternions and Euler angles. All exercises are stated first. Complete solutions appear only after the exercise section so that the article is self-study friendly.

Convention declaration

We use right-handed frames, Hamilton multiplication, scalar-first display notation, and the active 3-2-1 yaw-pitch-roll convention

$\displaystyle R = R_z(\psi)R_y(\theta)R_x(\phi), \qquad q = q_z(\psi)q_y(\theta)q_x(\phi).$ (1)

Exercises

Exercise 1

Show that a pure yaw of angle $\psi$ is represented by
$\displaystyle q = \cos\frac{\psi}{2} + \mathbf k\sin\frac{\psi}{2}.$ (2)

Exercise 2

Show that a pure pitch of angle $\theta$ is represented by
$\displaystyle q = \cos\frac{\theta}{2} + \mathbf j\sin\frac{\theta}{2}.$ (3)

Exercise 3

Show that a pure roll of angle $\phi$ is represented by
$\displaystyle q = \cos\frac{\phi}{2} + \mathbf i\sin\frac{\phi}{2}.$ (4)

Exercise 4

Multiply $q = q_z(\psi)q_y(\theta)q_x(\phi)$ and derive the 3-2-1 quaternion components.

Exercise 5

For
$\displaystyle \phi = 0, \qquad \theta = 0, \qquad \psi = \frac{\pi}{2},$ (5)
compute the corresponding quaternion.

Exercise 6

For
$\displaystyle \phi = \frac{\pi}{2}, \qquad \theta = 0, \qquad \psi = 0,$ (6)
compute the corresponding quaternion.

Exercise 7

For
$\displaystyle \phi = 0, \qquad \theta = \frac{\pi}{2}, \qquad \psi = 0,$ (7)
compute the corresponding quaternion.

Exercise 8

Write the 3-2-1 rotation matrix $R = R_z(\psi)R_y(\theta)R_x(\phi)$ explicitly.

Exercise 9

Show that the quaternion from Exercise 5 produces the same matrix as the 3-2-1 matrix with $\phi=0$, $\theta=0$, and $\psi=\pi/2$.

Exercise 10

Given a unit quaternion
$\displaystyle q = \frac{\sqrt3}{2} + \frac{1}{2}\mathbf k,$ (8)
recover the 3-2-1 yaw, pitch, and roll angles.

Exercise 11

Given a unit quaternion
$\displaystyle q = \frac{\sqrt2}{2} + \frac{\sqrt2}{2}\mathbf i,$ (9)
recover the 3-2-1 yaw, pitch, and roll angles.

Exercise 12

Explain why the 3-2-1 Euler angle description becomes singular at $\theta=\pm\pi/2$.

Exercise 13

A student uses a scalar-last quaternion array $[q_x,q_y,q_z,q_w]^T$ directly in a scalar-first Euler angle formula. Explain the error.

Exercise 14

Why can two different triples $(\phi,\theta,\psi)$ describe the same physical orientation?

Exercise 15

What is the practical advantage of propagating attitude with quaternions while still displaying yaw, pitch, and roll to a user?

Solutions

Solution 1

A yaw is a rotation about the $z$ axis, so its axis quaternion is
$\displaystyle q = \cos\frac{\psi}{2} + \mathbf k\sin\frac{\psi}{2}.$ (10)

Solution 2

A pitch is a rotation about the $y$ axis, so
$\displaystyle q = \cos\frac{\theta}{2} + \mathbf j\sin\frac{\theta}{2}.$ (11)

Solution 3

A roll is a rotation about the $x$ axis, so
$\displaystyle q = \cos\frac{\phi}{2} + \mathbf i\sin\frac{\phi}{2}.$ (12)

Solution 4

Introduce the half-angle abbreviations $c_\phi$, $s_\phi$, $c_\theta$, $s_\theta$, $c_\psi$, and $s_\psi$. Multiplying $q_z(\psi)q_y(\theta)q_x(\phi)$ gives
$\displaystyle q_w = c_\phi c_\theta c_\psi + s_\phi s_\theta s_\psi,$ (13)
$\displaystyle q_x = s_\phi c_\theta c_\psi - c_\phi s_\theta s_\psi,$ (14)
$\displaystyle q_y = c_\phi s_\theta c_\psi + s_\phi c_\theta s_\psi,$ (15)
$\displaystyle q_z = c_\phi c_\theta s_\psi - s_\phi s_\theta c_\psi.$ (16)

Solution 5

Substituting $\phi=0$, $\theta=0$, and $\psi=\pi/2$ gives
$\displaystyle q = \cos\frac{\pi}{4} + \mathbf k\sin\frac{\pi}{4} = \frac{1+\mathbf k}{\sqrt2}.$ (17)

Solution 6

Substituting $\phi=\pi/2$, $\theta=0$, and $\psi=0$ gives
$\displaystyle q = \cos\frac{\pi}{4} + \mathbf i\sin\frac{\pi}{4} = \frac{1+\mathbf i}{\sqrt2}.$ (18)

Solution 7

Substituting $\phi=0$, $\theta=\pi/2$, and $\psi=0$ gives
$\displaystyle q = \cos\frac{\pi}{4} + \mathbf j\sin\frac{\pi}{4} = \frac{1+\mathbf j}{\sqrt2}.$ (19)

Solution 8

The explicit matrix is
$\displaystyle R = \begin{bmatrix} c_\psi c_\theta & c_\psi s_\theta s_\phi - s_... ...- c_\psi s_\phi\ -s_\theta & c_\theta s_\phi & c_\theta c_\phi \end{bmatrix}.$ (20)

Solution 9

The quaternion of Exercise 5 is $q=(1+\mathbf k)/\sqrt2$. By Q09 its matrix is
$\displaystyle R(q)= \begin{bmatrix} 0 & -1 & 0\ 1 & 0 & 0\ 0 & 0 & 1 \end{bmatrix}.$ (21)
Setting $\phi=0$, $\theta=0$, and $\psi=\pi/2$ in the 3-2-1 matrix gives the same result.

Solution 10

Comparing with $q = \cos(\psi/2) + \mathbf k\sin(\psi/2)$ shows
$\displaystyle \psi = \frac{\pi}{3}, \qquad \theta = 0, \qquad \phi = 0.$ (22)
So the orientation is a pure yaw of $60^\circ$.

Solution 11

Comparing with $q = \cos(\phi/2) + \mathbf i\sin(\phi/2)$ shows
$\displaystyle \phi = \frac{\pi}{2}, \qquad \theta = 0, \qquad \psi = 0.$ (23)
So the orientation is a pure roll of $90^\circ$.

Solution 12

At $\theta=\pm\pi/2$, the yaw and roll axes align. The mapping from orientation to the triple $(\phi,\theta,\psi)$ therefore loses rank and one combination of yaw and roll becomes indistinguishable. This is the Euler angle singularity called gimbal lock.

Solution 13

The formulas assume that the first component is the scalar part $q_w$. If the array order is actually $[q_x,q_y,q_z,q_w]^T$, then the symbols are being matched to the wrong numerical entries. The components must be remapped before using the scalar-first formula.

Solution 14

Euler angles are not a unique global parameterization. Because rotations are periodic and because of the singular structure of the coordinate chart, different triples can represent the same orientation. For example, adding $2\pi$ to one angle may leave the physical orientation unchanged.

Solution 15

Quaternions are numerically robust for propagation, interpolation, and control, and they avoid gimbal-lock singularities. Euler angles, however, are intuitive for humans. A common strategy is therefore to compute internally with quaternions and display yaw, pitch, and roll externally.

License

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



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

This object's parent.

Cross-references: scalar, formula, matrix, quaternion, section, quaternions and Euler angles

This is version 1 of example of quaternions and Euler angles, born on 2026-08-24.
Object id is 1104, canonical name is ExampleOfQuaternionsAndEulerAngles.
Accessed 9 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)