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

<record version="1" id="1108">
 <title>example of relative attitude and error quaternions</title>
 <name>ExampleOfRelativeAttitudeAndErrorQuaternions</name>
 <created>2026-08-24 02:33:14</created>
 <modified>2026-08-24 02:33:14</modified>
 <type>Example</type>
<parent id="1107">relative attitude and error quaternions</parent>
 <creator id="1" name="bloftin"/>
 <modifier id="1" name="bloftin"/>
 <comment>converted to passive rotation notation</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>relative attitude</term>
	<term>error quaternion</term>
	<term>attitude error</term>
	<term>multiplicative error</term>
	<term>small angle approximation</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*{Relative attitude and error quaternions: examples, exercises, and solutions}

This companion article belongs to the PhysicsLibrary entry
\emph{Relative attitude and error quaternions}.  All exercises are stated
first.  Complete solutions appear only after the exercise section.

\section{Convention declaration}

We use the actual attitude $q$, desired attitude $q_d$, left error
\begin{equation}
\delta q_I=q_dq^*,
\end{equation}
and right error
\begin{equation}
\delta q_B=q^*q_d.
\end{equation}
The quaternions are unit, Hamilton multiplication is used, and components are
displayed scalar first.

\section{Exercises}

\subsection*{Exercise 1}
Starting from $q_d=\delta q_Iq$, derive
$\delta q_I=q_dq^*$.

\subsection*{Exercise 2}
Starting from $q_d=q\delta q_B$, derive
$\delta q_B=q^*q_d$.

\subsection*{Exercise 3}
Show that the two error definitions satisfy
\begin{equation}
\delta q_I=q\delta q_Bq^*.
\end{equation}

\subsection*{Exercise 4}
The actual attitude is a $10^\circ$ yaw and the desired attitude is a
$25^\circ$ yaw.  Find the exact error quaternion and its axis angle form.

\subsection*{Exercise 5}
The actual attitude is
\begin{equation}
q=\frac{1+\mathbf i}{\sqrt2},
\end{equation}
and the desired attitude is
\begin{equation}
q_d=\frac{1+\mathbf j}{\sqrt2}.
\end{equation}
Compute the left error $\delta q_I=q_dq^*$.

\subsection*{Exercise 6}
For the same attitudes as Exercise 5, compute the right error
$\delta q_B=q^*q_d$ and verify that it differs from the left error.

\subsection*{Exercise 7}
Given
\begin{equation}
\delta q=0.9659258+0.2588190\mathbf k,
\end{equation}
recover the exact error angle and axis.

\subsection*{Exercise 8}
Given the small error quaternion
\begin{equation}
\delta q=(0.999825,\,0.005,\,-0.010,\,0.015),
\end{equation}
estimate the small rotation vector using the first order approximation.

\subsection*{Exercise 9}
A relative quaternion is computed as
\begin{equation}
\delta q=(-0.9998,\,0.010,\,-0.005,\,0.015).
\end{equation}
Choose the equivalent representative appropriate for a principal small error
interpretation and estimate the small rotation vector.

\subsection*{Exercise 10}
Show that if
\begin{equation}
\delta q\approx
\begin{bmatrix}
1\\[1mm]
\frac12\delta\boldsymbol\theta
\end{bmatrix},
\end{equation}
then the norm error is second order in
$\lVert\delta\boldsymbol\theta\rVert$.

\subsection*{Exercise 11}
Suppose the actual attitude is exactly equal to the desired physical attitude,
but the stored quaternions are $q$ and $q_d=-q$.  Compute
$q_dq^*$ and explain why this is not a large physical attitude error.

\subsection*{Exercise 12}
If a small right error is
\begin{equation}
\delta\boldsymbol\theta^B=
\begin{bmatrix}
0.01\\-0.02\\0.03
\end{bmatrix}\ \mathrm{rad}
\end{equation}
and the current attitude matrix is $R(q)$, write the expression for the
corresponding inertial resolved small error.

\subsection*{Exercise 13}
An error state estimator uses a right error but injects its correction according
to $q^+=\delta q\widehat q$.  What is inconsistent about this update?

\subsection*{Exercise 14}
Why is the raw difference between desired and actual yaw-pitch-roll triples not,
in general, an exact attitude error vector?

\subsection*{Exercise 15}
A controller receives an error quaternion with scalar part near zero.  What
physical attitude error magnitude does this indicate, and why should sign
selection be handled carefully there?

\subsection*{Exercise 16}
Let the principal error quaternion be
\begin{equation}
\delta q=0.9238795+
\frac{0.3826834}{\sqrt3}(\mathbf i+\mathbf j+\mathbf k).
\end{equation}
Find the error axis, exact angle, and first order small angle approximation.
Comment on whether the first order approximation is appropriate.

\section{Solutions}

\subsection*{Solution 1}
From
\begin{equation}
q_d=\delta q_Iq,
\end{equation}
right multiply by $q^*$.  Since $qq^*=1$,
\begin{equation}
\boxed{\delta q_I=q_dq^*.}
\end{equation}

\subsection*{Solution 2}
From
\begin{equation}
q_d=q\delta q_B,
\end{equation}
left multiply by $q^*$.  Since $q^*q=1$,
\begin{equation}
\boxed{\delta q_B=q^*q_d.}
\end{equation}

\subsection*{Solution 3}
Substitute the right error into the expression
$q\delta q_Bq^*$:
\begin{equation}
q\delta q_Bq^*
=q(q^*q_d)q^*
=(qq^*)q_dq^*
=q_dq^*.
\end{equation}
Therefore
\begin{equation}
\boxed{\delta q_I=q\delta q_Bq^*.}
\end{equation}

\subsection*{Solution 4}
The desired yaw exceeds the actual yaw by $15^\circ$, so
\begin{equation}
\boxed{
\delta q=
\cos7.5^\circ+\mathbf k\sin7.5^\circ.
}
\end{equation}
The error axis is $+\hat{\mathbf z}$ and the error angle is $15^\circ$.

\subsection*{Solution 5}
Here
\begin{equation}
q^*=\frac{1-\mathbf i}{\sqrt2}.
\end{equation}
Therefore
\begin{equation}
\begin{aligned}
\delta q_I
&amp;=\frac12(1+\mathbf j)(1-\mathbf i)\\
&amp;=\frac12(1-\mathbf i+\mathbf j+\mathbf k),
\end{aligned}
\end{equation}
because $\mathbf j\mathbf i=-\mathbf k$.

\subsection*{Solution 6}
The right error is
\begin{equation}
\begin{aligned}
\delta q_B
&amp;=\frac12(1-\mathbf i)(1+\mathbf j)\\
&amp;=\frac12(1-\mathbf i+\mathbf j-\mathbf k),
\end{aligned}
\end{equation}
because $\mathbf i\mathbf j=\mathbf k$.  The $\mathbf k$ component has the
opposite sign from the left error.  The two describe the same relative rotation
resolved in different coordinates.

\subsection*{Solution 7}
The scalar and vector magnitudes are
\begin{equation}
\delta q_w=0.9659258,
\qquad
\lVert\delta\mathbf q_v\rVert=0.2588190.
\end{equation}
Thus
\begin{equation}
\delta\theta=2\operatorname{atan2}(0.2588190,0.9659258)=30^\circ.
\end{equation}
The axis is $+\hat{\mathbf z}$.

\subsection*{Solution 8}
For small error,
\begin{equation}
\delta\boldsymbol\theta\approx2\delta\mathbf q_v.
\end{equation}
Therefore
\begin{equation}
\boxed{
\delta\boldsymbol\theta
\approx
\begin{bmatrix}
0.010\\-0.020\\0.030
\end{bmatrix}\ \mathrm{rad}.
}
\end{equation}

\subsection*{Solution 9}
Choose the equivalent sign with positive scalar part:
\begin{equation}
\delta q'=(0.9998,\,-0.010,\,0.005,\,-0.015).
\end{equation}
Then
\begin{equation}
\boxed{
\delta\boldsymbol\theta
\approx
\begin{bmatrix}
-0.020\\0.010\\-0.030
\end{bmatrix}\ \mathrm{rad}.
}
\end{equation}

\subsection*{Solution 10}
The squared norm of the first order approximation is
\begin{equation}
\left\lVert
\begin{bmatrix}
1\\[1mm]\frac12\delta\boldsymbol\theta
\end{bmatrix}
\right\rVert^2
=1+\frac14\lVert\delta\boldsymbol\theta\rVert^2.
\end{equation}
Hence the departure from unit norm is second order in the small rotation
magnitude.

\subsection*{Solution 11}
If $q_d=-q$, then
\begin{equation}
q_dq^*=-(qq^*)=-1.
\end{equation}
The quaternions $+1$ and $-1$ both represent the identity physical rotation.
Thus the relative quaternion is an alternate representative of zero attitude
error, not a $360^\circ$ control correction.  For a local error model one would
flip the sign to $+1$.

\subsection*{Solution 12}
To first order,
\begin{equation}
\boxed{
\delta\boldsymbol\theta^I
=R(q)\delta\boldsymbol\theta^B.
}
\end{equation}
The numerical value cannot be found without the current attitude matrix.

\subsection*{Solution 13}
A right error convention requires correction on the right:
\begin{equation}
q^+=\widehat q\delta q.
\end{equation}
The proposed update multiplies on the left and therefore applies a left error
correction while the estimator covariance and Jacobians describe a right error.

\subsection*{Solution 14}
Euler angle coordinates depend on the chosen rotation sequence and are nonlinear
coordinates on orientation space.  Subtracting two angle triples does not, in
general, produce the axis and angle of the finite relative rotation.  The exact
relative rotation should first be formed with quaternions or matrices.

\subsection*{Solution 15}
For a unit error quaternion,
\begin{equation}
\delta q_w=\cos\frac{\delta\theta}{2}.
\end{equation}
A scalar part near zero therefore corresponds to an attitude error near
$180^\circ$.  At that point the choices $\delta q$ and $-\delta q$ are equally
valid principal representatives, so the sign can change under arbitrarily small
perturbations.

\subsection*{Solution 16}
The vector part is parallel to
\begin{equation}
\widehat{\mathbf u}_e=\frac{1}{\sqrt3}(1,1,1).
\end{equation}
Since
\begin{equation}
0.9238795=\cos22.5^\circ,
\qquad
0.3826834=\sin22.5^\circ,
\end{equation}
the exact error angle is
\begin{equation}
\boxed{\delta\theta=45^\circ.}
\end{equation}
The first order estimate would be
\begin{equation}
\delta\boldsymbol\theta
\approx
\frac{0.7653668}{\sqrt3}
\begin{bmatrix}1\\1\\1\end{bmatrix}
\ \mathrm{rad}.
\end{equation}
Its magnitude is about $0.765$ rad, whereas the exact angle is
$\pi/4\approx0.785$ rad.  The approximation is already noticeably imperfect;
for a $45^\circ$ error the exact quaternion should be retained.

\section*{License}

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