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

<record version="2" id="1103">
 <title>quaternions and Euler angles</title>
 <name>QuaternionsAndEulerAngles</name>
 <created>2026-08-24 01:56:23</created>
 <modified>2026-08-24 02:08:08</modified>
 <type>Topic</type>
 <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>Tait-Bryan angles</term>
	<term>gimbal lock</term>
	<term>attitude parameterization</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}

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.

\section{Convention declaration}

This article uses the PhysicsLibrary house convention:
\begin{enumerate}
\item right-handed orthonormal frames;
\item Hamilton multiplication, so $\mathbf i\mathbf j=\mathbf k$;
\item scalar-first display notation,
\begin{equation}
q=q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k;
\end{equation}
\item active vector rotation,
\begin{equation}
\mathbf v' = q\mathbf v q^* = R(q)\mathbf v.
\end{equation}
\end{enumerate}

The specific Euler angle convention treated here is the\linebreak
\emph{3-2-1 yaw-pitch-roll sequence}.  In matrix form we define
\begin{equation}
\boxed{R = R_z(\psi)R_y(\theta)R_x(\phi),}
\end{equation}
where
\begin{equation}
\psi = \text{yaw},
\qquad
\theta = \text{pitch},
\qquad
\phi = \text{roll}.
\end{equation}
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.

\section{Euler angle families}

There are two broad families of Euler angle sequences.
\begin{enumerate}
\item \emph{Proper Euler angle sequences} reuse one axis, for example 3-1-3.
\item \emph{Tait-Bryan sequences} use three distinct axes, for example 3-2-1.
\end{enumerate}
The yaw-pitch-roll convention of engineering and aerospace work is a Tait-Bryan
sequence.

\section{Elementary axis quaternions}

A rotation of angle $\alpha$ about the positive $x$ axis is represented by
\begin{equation}
q_x(\alpha)=\cos\frac{\alpha}{2}+\mathbf i\sin\frac{\alpha}{2}.
\end{equation}
Similarly,
\begin{equation}
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}.
\end{equation}
Therefore the unit quaternion corresponding to the 3-2-1 sequence is
\begin{equation}
\boxed{q = q_z(\psi)q_y(\theta)q_x(\phi).}
\end{equation}
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)$.

\section{Step-by-step geometry}

Figure~\ref{fig:q10-sequence} illustrates the stepwise 3-2-1 sequence.  The
yaw, pitch, and roll arcs are shown in different colors to distinguish the
three elementary rotations.

\begin{figure}[h]
\centering
\includegraphics[width=0.97\textwidth]{Q10_euler_sequence.png}
\caption{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)$.}
\label{fig:q10-sequence}
\end{figure}

\section{Quaternion formula for the 3-2-1 sequence}

Introduce the half-angle abbreviations
\begin{equation}
c_\phi = \cos\frac{\phi}{2},
\qquad
s_\phi = \sin\frac{\phi}{2},
\end{equation}
\begin{equation}
c_\theta = \cos\frac{\theta}{2},
\qquad
s_\theta = \sin\frac{\theta}{2},
\end{equation}
\begin{equation}
c_\psi = \cos\frac{\psi}{2},
\qquad
s_\psi = \sin\frac{\psi}{2}.
\end{equation}
Then
\begin{equation}
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.
\end{equation}
Multiplying the three factors gives
\begin{equation}
\boxed{
q = q_w + q_x\mathbf i + q_y\mathbf j + q_z\mathbf k,
}
\end{equation}
with components
\begin{equation}
\boxed{
q_w = c_\phi c_\theta c_\psi + s_\phi s_\theta s_\psi,
}
\end{equation}
\begin{equation}
\boxed{
q_x = s_\phi c_\theta c_\psi - c_\phi s_\theta s_\psi,
}
\end{equation}
\begin{equation}
\boxed{
q_y = c_\phi s_\theta c_\psi + s_\phi c_\theta s_\psi,
}
\end{equation}
\begin{equation}
\boxed{
q_z = c_\phi c_\theta s_\psi - s_\phi s_\theta c_\psi.
}
\end{equation}
These are among the most frequently used formulas in navigation,
flight-dynamics, robotics, and graphics software.

\section{The associated 3-2-1 rotation matrix}

The same sequence has matrix form
\begin{equation}
\boxed{
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}
Equating this matrix with the quaternion-generated matrix of Q09 provides a
useful cross-check of the component formulas in equations (13) through (16).

\section{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
\begin{equation}
\boxed{
\phi = \operatorname{atan2}\!\left(2(q_w q_x + q_y q_z),\ 1-2(q_x^2+q_y^2)\right),
}
\end{equation}
\begin{equation}
\boxed{
\theta = \arcsin\!\left(2(q_w q_y - q_z q_x)\right),
}
\end{equation}
\begin{equation}
\boxed{
\psi = \operatorname{atan2}\!\left(2(q_w q_z + q_x q_y),\ 1-2(q_y^2+q_z^2)\right).
}
\end{equation}
These formulas assume the same 3-2-1 convention and the same active/Hamilton
sign conventions used above.

\section{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
\begin{equation}
\boxed{\theta = \pm \frac{\pi}{2}.}
\end{equation}
At this pitch angle the yaw and roll axes align, and the decomposition loses one
degree of freedom.  In engineering language this is called \emph{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.

\section{A simple example}

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

\section{Common pitfalls}

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

\section{What comes next}

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

\section{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.

\section*{License}

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