<?xml version="1.0" encoding="UTF-8"?>

<record version="1" id="1104">
 <title>example of quaternions and Euler angles</title>
 <name>ExampleOfQuaternionsAndEulerAngles</name>
 <created>2026-08-24 02:05:28</created>
 <modified>2026-08-24 02:05:28</modified>
 <type>Example</type>
<parent id="1103">quaternions and Euler angles</parent>
 <creator id="1" name="bloftin"/>
 <modifier id="1" name="bloftin"/>
 <comment>converted to the passive rotation convention</comment>
 <author id="1" name="bloftin"/>
 <classification>
	<category scheme="pacs" code="02.40.Yy"/>
	<category scheme="pacs" code="02.10.Hh"/>
	<category scheme="pacs" code="45.40.-f"/>
 </classification>
 <keywords>
	<term>quaternion</term>
	<term>Euler angles</term>
	<term>yaw pitch roll</term>
	<term>321 sequence</term>
	<term>gimbal lock</term>
	<term>Tait-Bryan angles</term>
	<term>exercises</term>
	<term>worked solutions</term>
 </keywords>
 <preamble>% this is the default PhysicsLibrary preamble.  as your knowledge
% of TeX increases, you will probably want to edit this, but
% it should be fine as is for beginners.

% almost certainly you want these
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}

% used for TeXing text within eps files
%\usepackage{psfrag}
% need this for including graphics (\includegraphics).
% If you use \includegraphics{figure} with no file extension, PhysicsLibrary
% will prefer figure.png before falling back to figure.eps.
\usepackage{graphicx}
\DeclareGraphicsExtensions{.png,.jpg,.jpeg,.pdf,.eps}
% for neatly defining theorems and propositions
%\usepackage{amsthm}
% making logically defined graphics
%\usepackage{xypic}

% there are many more packages, add them here as you need them

% define commands here</preamble>
 <content>\section*{Quaternions and Euler Angles: Examples, Exercises, and Solutions}

This companion article belongs to the PhysicsLibrary entry
\emph{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.

\section{Convention declaration}

We use right-handed frames, Hamilton multiplication, scalar-first display
notation, and the active 3-2-1 yaw-pitch-roll convention
\begin{equation}
R = R_z(\psi)R_y(\theta)R_x(\phi),
\qquad
q = q_z(\psi)q_y(\theta)q_x(\phi).
\end{equation}

\section{Exercises}

\subsection*{Exercise 1}
Show that a pure yaw of angle $\psi$ is represented by
\begin{equation}
q = \cos\frac{\psi}{2} + \mathbf k\sin\frac{\psi}{2}.
\end{equation}

\subsection*{Exercise 2}
Show that a pure pitch of angle $\theta$ is represented by
\begin{equation}
q = \cos\frac{\theta}{2} + \mathbf j\sin\frac{\theta}{2}.
\end{equation}

\subsection*{Exercise 3}
Show that a pure roll of angle $\phi$ is represented by
\begin{equation}
q = \cos\frac{\phi}{2} + \mathbf i\sin\frac{\phi}{2}.
\end{equation}

\subsection*{Exercise 4}
Multiply
$q = q_z(\psi)q_y(\theta)q_x(\phi)$ and derive the 3-2-1 quaternion components.

\subsection*{Exercise 5}
For
\begin{equation}
\phi = 0,
\qquad
\theta = 0,
\qquad
\psi = \frac{\pi}{2},
\end{equation}
compute the corresponding quaternion.

\subsection*{Exercise 6}
For
\begin{equation}
\phi = \frac{\pi}{2},
\qquad
\theta = 0,
\qquad
\psi = 0,
\end{equation}
compute the corresponding quaternion.

\subsection*{Exercise 7}
For
\begin{equation}
\phi = 0,
\qquad
\theta = \frac{\pi}{2},
\qquad
\psi = 0,
\end{equation}
compute the corresponding quaternion.

\subsection*{Exercise 8}
Write the 3-2-1 rotation matrix
$R = R_z(\psi)R_y(\theta)R_x(\phi)$ explicitly.

\subsection*{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$.

\subsection*{Exercise 10}
Given a unit quaternion
\begin{equation}
q = \frac{\sqrt3}{2} + \frac{1}{2}\mathbf k,
\end{equation}
recover the 3-2-1 yaw, pitch, and roll angles.

\subsection*{Exercise 11}
Given a unit quaternion
\begin{equation}
q = \frac{\sqrt2}{2} + \frac{\sqrt2}{2}\mathbf i,
\end{equation}
recover the 3-2-1 yaw, pitch, and roll angles.

\subsection*{Exercise 12}
Explain why the 3-2-1 Euler angle description becomes singular at
$\theta=\pm\pi/2$.

\subsection*{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.

\subsection*{Exercise 14}
Why can two different triples $(\phi,\theta,\psi)$ describe the same physical
orientation?

\subsection*{Exercise 15}
What is the practical advantage of propagating attitude with quaternions while
still displaying yaw, pitch, and roll to a user?

\section{Solutions}

\subsection*{Solution 1}
A yaw is a rotation about the $z$ axis, so its axis quaternion is
\begin{equation}
q = \cos\frac{\psi}{2} + \mathbf k\sin\frac{\psi}{2}.
\end{equation}

\subsection*{Solution 2}
A pitch is a rotation about the $y$ axis, so
\begin{equation}
q = \cos\frac{\theta}{2} + \mathbf j\sin\frac{\theta}{2}.
\end{equation}

\subsection*{Solution 3}
A roll is a rotation about the $x$ axis, so
\begin{equation}
q = \cos\frac{\phi}{2} + \mathbf i\sin\frac{\phi}{2}.
\end{equation}

\subsection*{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
\begin{equation}
q_w = c_\phi c_\theta c_\psi + s_\phi s_\theta s_\psi,
\end{equation}
\begin{equation}
q_x = s_\phi c_\theta c_\psi - c_\phi s_\theta s_\psi,
\end{equation}
\begin{equation}
q_y = c_\phi s_\theta c_\psi + s_\phi c_\theta s_\psi,
\end{equation}
\begin{equation}
q_z = c_\phi c_\theta s_\psi - s_\phi s_\theta c_\psi.
\end{equation}

\subsection*{Solution 5}
Substituting $\phi=0$, $\theta=0$, and $\psi=\pi/2$ gives
\begin{equation}
q = \cos\frac{\pi}{4} + \mathbf k\sin\frac{\pi}{4}
= \frac{1+\mathbf k}{\sqrt2}.
\end{equation}

\subsection*{Solution 6}
Substituting $\phi=\pi/2$, $\theta=0$, and $\psi=0$ gives
\begin{equation}
q = \cos\frac{\pi}{4} + \mathbf i\sin\frac{\pi}{4}
= \frac{1+\mathbf i}{\sqrt2}.
\end{equation}

\subsection*{Solution 7}
Substituting $\phi=0$, $\theta=\pi/2$, and $\psi=0$ gives
\begin{equation}
q = \cos\frac{\pi}{4} + \mathbf j\sin\frac{\pi}{4}
= \frac{1+\mathbf j}{\sqrt2}.
\end{equation}

\subsection*{Solution 8}
The explicit matrix is
\begin{equation}
R =
\begin{bmatrix}
c_\psi c_\theta &amp; c_\psi s_\theta s_\phi - s_\psi c_\phi &amp; c_\psi s_\theta c_\phi + s_\psi s_\phi\\
s_\psi c_\theta &amp; s_\psi s_\theta s_\phi + c_\psi c_\phi &amp; s_\psi s_\theta c_\phi - c_\psi s_\phi\\
-s_\theta &amp; c_\theta s_\phi &amp; c_\theta c_\phi
\end{bmatrix}.
\end{equation}

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

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

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

\subsection*{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.

\subsection*{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.

\subsection*{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.

\subsection*{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.

\section*{License}

This article is an original synthesis prepared for PhysicsLibrary and intended
for release under CC BY-SA 4.0.</content>
</record>
