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

<record version="1" id="1096">
 <title>example of Axis Angle Representation and Unit Quaternion</title>
 <name>ExampleOfAxisAngleRepresentationAndUnitQuaternion</name>
 <created>2026-08-23 20:15:27</created>
 <modified>2026-08-23 20:15:27</modified>
 <type>Example</type>
<parent id="1095">Axis Angle Representation and Unit Quaternion</parent>
 <creator id="1" name="bloftin"/>
 <modifier id="1" name="bloftin"/>
 <comment>converted to passive rotation convention</comment>
 <author id="1" name="bloftin"/>
 <classification>
	<category scheme="pacs" code="02.40.Yy"/>
	<category scheme="pacs" code="02.10.Hh"/>
 </classification>
 <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)
%\usepackage{graphicx}
% 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*{Axis Angle Representation and Unit Quaternion: Examples, Exercises, and Solutions}

This companion entry is designed for self study after the PhysicsLibrary article
\emph{Axis Angle Representation and Unit Quaternion}.  All exercises are given
first so that a reader can work through the full set without encountering the
solutions accidentally.  Complete solutions follow in a separate section.

Unless otherwise stated, use Hamilton multiplication, scalar-first quaternion
components, right-handed Cartesian axes, and the PhysicsLibrary active rotation
convention
\begin{equation}
\boxed{
q
=\cos\frac{\theta}{2}
+\widehat{\mathbf u}\sin\frac{\theta}{2}.
}
\end{equation}
Angles are positive according to the right-hand rule about
$\widehat{\mathbf u}$.

\section{Exercises}

\subsection*{Foundational exercises}

\begin{enumerate}
\item \textbf{$90^\circ$ about the $z$ axis.}
Construct the unit quaternion for a positive active rotation of $90^\circ$ about
$+\widehat{\mathbf z}$.  Give the answer both as
$q=q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k$ and as a scalar-first column.

\item \textbf{$120^\circ$ about the $(1,1,1)$ axis.}
Construct the quaternion for a positive active rotation of $120^\circ$ about
\[
\widehat{\mathbf u}=\frac{1}{\sqrt3}(1,1,1).
\]
Verify directly that the quaternion has unit norm.

\item \textbf{A nontrivial normalized axis.}
Construct the quaternion for a rotation of $60^\circ$ about the axis
\[
\widehat{\mathbf u}=\frac13(1,2,2).
\]
Write the exact scalar-first components.

\item \textbf{Recover an axis and angle.}
For
\[
q=\left(\frac{\sqrt2}{2},\;0,\;\frac{\sqrt2}{2},\;0\right),
\]
recover the principal axis and angle.

\item \textbf{A $180^\circ$ quaternion.}
For the unit quaternion
\[
q=\left(0,\;\frac13,\;-\frac23,\;\frac23\right),
\]
find the axis and angle.  Explain what happens if the quaternion is replaced by
$-q$.
\end{enumerate}

\subsection*{Convention and interpretation exercises}

\begin{enumerate}
\setcounter{enumi}{5}
\item \textbf{The $q$ versus $-q$ ambiguity.}
Let
\[
q=\cos 20^\circ+\mathbf k\sin20^\circ.
\]
Determine the physical axis and angle represented by $q$.  Then express $-q$
as an axis angle pair with an angle in the interval $[0,2\pi]$ and show that it
represents the same physical rotation.

\item \textbf{Zero, $2\pi$, and $4\pi$.}
For a fixed unit axis $\widehat{\mathbf u}$, evaluate the quaternion for physical
rotation angles $0$, $2\pi$, and $4\pi$.  Which of these quaternions are equal?
Which represent the same physical orientation?

\item \textbf{Active inverse and passive counterpart.}
Write the quaternion for a positive active rotation of $30^\circ$ about
$+\widehat{\mathbf z}$.  Then find its inverse.  Interpret the inverse as both
(a) an active rotation and (b) the corresponding opposite-direction passive
coordinate transformation.

\item \textbf{The nonunit axis trap.}
A programmer attempts to construct a $90^\circ$ rotation about the $x$ axis
using the vector $(2,0,0)$ directly in
\[
q=\cos\frac{\theta}{2}+\mathbf u\sin\frac{\theta}{2}.
\]
Compute the resulting quaternion and its norm.  Explain the mistake and give the
correct unit quaternion.
\end{enumerate}

\subsection*{Engineering and derivation exercises}

\begin{enumerate}
\setcounter{enumi}{9}
\item \textbf{Small attitude correction.}
An attitude estimator produces the small rotation vector
\[
\delta\boldsymbol\theta
=\begin{bmatrix}0.01&amp;-0.02&amp;0.03\end{bmatrix}^{T}\ \text{rad}.
\]
Use the first order small angle quaternion approximation to form the correction
quaternion.  Compute its norm to show the size of the first order normalization
error.  Then give the normalized approximation.

\item \textbf{Engineering command axis.}
A spacecraft is commanded to rotate by $15^\circ$ about the body fixed unit axis
\[
\widehat{\mathbf u}=\frac13(2,-1,2).
\]
Construct the exact command quaternion and give numerical component values to at
least six significant digits.

\item \textbf{Derive the half angle.}
Let $\widehat{\mathbf u}$ and $\mathbf v$ be perpendicular unit pure
quaternions and let
\[
q=\cos\phi+\widehat{\mathbf u}\sin\phi.
\]
Starting from $q\mathbf vq^*$, prove that the vector is rotated through physical
angle $2\phi$.  Hence explain why a desired physical angle $\theta$ is encoded
with quaternion phase $\theta/2$.

\item \textbf{Derive the quaternion exponential.}
Using only $\widehat{\mathbf u}^{\,2}=-1$ and the power series definition of the
exponential, prove
\[
\exp(\widehat{\mathbf u}\phi)
=\cos\phi+\widehat{\mathbf u}\sin\phi.
\]
Then write the axis angle quaternion as an exponential.

\item \textbf{Principal representative from a negative scalar part.}
A normalized attitude quaternion is received as
\[
q=(-0.9238795,\;0,\;0,\;-0.3826834).
\]
First extract an axis angle pair using the quaternion exactly as given.  Then
choose the equivalent representative with nonnegative scalar part and extract
the principal rotation with angle in $[0,\pi]$.  Explain why both describe the
same orientation.
\end{enumerate}

\section{Solutions}

\subsection*{Solution 1: $90^\circ$ about the $z$ axis}

Here
\[
\widehat{\mathbf u}=\mathbf k,
\qquad
\frac{\theta}{2}=45^\circ.
\]
Therefore
\begin{equation}
\boxed{
q
=\cos45^\circ+\mathbf k\sin45^\circ
=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k.
}
\end{equation}
In scalar-first column form,
\begin{equation}
\boxed{
q=
\begin{bmatrix}
\sqrt2/2\\0\\0\\\sqrt2/2
\end{bmatrix}.
}
\end{equation}

\subsection*{Solution 2: $120^\circ$ about $(1,1,1)$}

The half angle is $60^\circ$, so
\[
\cos60^\circ=\frac12,
\qquad
\sin60^\circ=\frac{\sqrt3}{2}.
\]
Multiplying the sine by the axis gives
\[
\frac{\sqrt3}{2}
\frac1{\sqrt3}(1,1,1)
=\frac12(1,1,1).
\]
Thus
\begin{equation}
\boxed{
q=\frac12
+\frac12\mathbf i
+\frac12\mathbf j
+\frac12\mathbf k.
}
\end{equation}
Its squared norm is
\[
\lVert q\rVert^2
=\frac14+\frac14+\frac14+\frac14=1.
\]

\subsection*{Solution 3: $60^\circ$ about $(1,2,2)/3$}

The axis is already unit because
\[
\frac{1^2+2^2+2^2}{3^2}=1.
\]
The half angle is $30^\circ$, with
\[
\cos30^\circ=\frac{\sqrt3}{2},
\qquad
\sin30^\circ=\frac12.
\]
Therefore
\begin{equation}
\boxed{
q
=\frac{\sqrt3}{2}
+\frac16\mathbf i
+\frac13\mathbf j
+\frac13\mathbf k.
}
\end{equation}

\subsection*{Solution 4: recover an axis and angle}

The scalar part is
\[
q_w=\frac{\sqrt2}{2},
\]
and the vector part magnitude is
\[
s=\frac{\sqrt2}{2}.
\]
Hence
\begin{equation}
\theta
=2\operatorname{atan2}\left(\frac{\sqrt2}{2},\frac{\sqrt2}{2}\right)
=2\left(\frac{\pi}{4}\right)
=\frac{\pi}{2}.
\end{equation}
The axis is
\[
\widehat{\mathbf u}
=\frac{(0,\sqrt2/2,0)}{\sqrt2/2}
=(0,1,0).
\]
Thus the rotation is
\[
\boxed{+90^\circ\text{ about }+\widehat{\mathbf y}.}
\]

\subsection*{Solution 5: a $180^\circ$ quaternion}

Here $q_w=0$ and the vector part already has unit magnitude.  Therefore
\begin{equation}
\theta=2\operatorname{atan2}(1,0)=\pi.
\end{equation}
The axis is
\begin{equation}
\boxed{
\widehat{\mathbf u}
=\frac13(1,-2,2).
}
\end{equation}
Replacing $q$ by $-q$ reverses the displayed axis.  At a $180^\circ$ rotation,
$+\widehat{\mathbf u}$ and $-\widehat{\mathbf u}$ describe the same physical
rotation, and the two quaternions differ only by the usual sign ambiguity.

\subsection*{Solution 6: $q$ versus $-q$}

The quaternion phase is $20^\circ$, so the physical angle is
\[
\theta=40^\circ,
\]
about $+\widehat{\mathbf z}$.

For the negative quaternion,
\[
-q=-\cos20^\circ-\mathbf k\sin20^\circ.
\]
Using an angle in $[0,2\pi]$,
\[
-\cos20^\circ=\cos160^\circ,
\qquad
-\sin20^\circ=-\sin160^\circ.
\]
Thus
\begin{equation}
-q
=\cos160^\circ
-\mathbf k\sin160^\circ.
\end{equation}
Its physical axis angle pair can therefore be written as
\[
\boxed{-\widehat{\mathbf z}\text{ through }320^\circ.}
\]
A $320^\circ$ rotation about $-\widehat{\mathbf z}$ is the same physical
orientation as a $40^\circ$ rotation about $+\widehat{\mathbf z}$.

\subsection*{Solution 7: zero, $2\pi$, and $4\pi$}

For a fixed axis,
\[
q(\theta)=\cos\frac{\theta}{2}
+\widehat{\mathbf u}\sin\frac{\theta}{2}.
\]
Therefore
\begin{equation}
\boxed{
q(0)=+1,
\qquad
q(2\pi)=-1,
\qquad
q(4\pi)=+1.
}
\end{equation}
The quaternions at $0$ and $4\pi$ are equal.  The quaternion at $2\pi$ is their
negative.  All three represent the same physical orientation.

\subsection*{Solution 8: active inverse and passive counterpart}

The positive active quaternion is
\begin{equation}
\boxed{
q=\cos15^\circ+\mathbf k\sin15^\circ.
}
\end{equation}
Because it is unit,
\begin{equation}
\boxed{
q^{-1}=q^*
=\cos15^\circ-\mathbf k\sin15^\circ.
}
\end{equation}
As an active rotation, $q^{-1}$ is a $-30^\circ$ rotation about
$+\widehat{\mathbf z}$, equivalently a $+30^\circ$ rotation about
$-\widehat{\mathbf z}$.  The same inverse relation appears when one reverses the
direction of a passive frame transformation.

\subsection*{Solution 9: the nonunit axis trap}

The programmer uses
\[
\mathbf u=2\mathbf i,
\qquad
\frac{\theta}{2}=45^\circ.
\]
This gives
\begin{equation}
q_{\rm bad}
=\frac{\sqrt2}{2}+\sqrt2\,\mathbf i.
\end{equation}
Its squared norm is
\[
\lVert q_{\rm bad}\rVert^2
=\frac12+2=\frac52,
\]
so
\begin{equation}
\boxed{\lVert q_{\rm bad}\rVert=\sqrt{\frac52}\neq1.}
\end{equation}
The mistake is using an axis vector of length two instead of a unit axis.  The
correct axis is $\widehat{\mathbf u}=\mathbf i$, giving
\begin{equation}
\boxed{
q
=\frac{\sqrt2}{2}
+\frac{\sqrt2}{2}\mathbf i.
}
\end{equation}

\subsection*{Solution 10: small attitude correction}

The first order approximation is
\[
q\approx
\begin{bmatrix}
1\\
\tfrac12(0.01)\\
\tfrac12(-0.02)\\
\tfrac12(0.03)
\end{bmatrix}
=\begin{bmatrix}
1\\0.005\\-0.010\\0.015
\end{bmatrix}.
\]
Its squared norm is
\[
1+0.005^2+0.010^2+0.015^2
=1.00035,
\]
so
\begin{equation}
\boxed{
\lVert q\rVert=\sqrt{1.00035}\approx1.000174985.
}
\end{equation}
Normalizing gives approximately
\begin{equation}
\boxed{
\widehat q
\approx
\begin{bmatrix}
0.99982505\\
0.00499913\\
-0.00999825\\
0.01499738
\end{bmatrix}.
}
\end{equation}
The norm error is second order, as expected from a first order small angle
approximation.

\subsection*{Solution 11: engineering command axis}

The half angle is
\[
\frac{\theta}{2}=7.5^\circ.
\]
Thus
\begin{equation}
q
=\cos7.5^\circ
+\frac13(2\mathbf i-\mathbf j+2\mathbf k)\sin7.5^\circ.
\end{equation}
Using
\[
\cos7.5^\circ\approx0.991444861,
\qquad
\sin7.5^\circ\approx0.130526192,
\]
we obtain
\begin{equation}
\boxed{
q\approx
\begin{bmatrix}
0.991444861\\
0.087017461\\
-0.043508731\\
0.087017461
\end{bmatrix}.
}
\end{equation}

\subsection*{Solution 12: derive the half angle}

Let
\[
c=\cos\phi,
\qquad
s=\sin\phi,
\qquad
q=c+s\widehat{\mathbf u}.
\]
Because $q$ is unit,
\[
q^*=c-s\widehat{\mathbf u}.
\]
For perpendicular unit pure quaternions,
\[
\widehat{\mathbf u}\mathbf v
=\widehat{\mathbf u}\times\mathbf v,
\qquad
\mathbf v\widehat{\mathbf u}
=-\widehat{\mathbf u}\times\mathbf v,
\qquad
\widehat{\mathbf u}\mathbf v\widehat{\mathbf u}=\mathbf v.
\]
Therefore
\begin{equation}
\begin{aligned}
q\mathbf vq^*
&amp;=(c+s\widehat{\mathbf u})\mathbf v
  (c-s\widehat{\mathbf u})\\
&amp;=(c^2-s^2)\mathbf v
+2cs(\widehat{\mathbf u}\times\mathbf v)\\
&amp;=\cos(2\phi)\mathbf v
+\sin(2\phi)(\widehat{\mathbf u}\times\mathbf v).
\end{aligned}
\end{equation}
This is a planar rotation of $\mathbf v$ by $2\phi$ about
$\widehat{\mathbf u}$.  Hence
\begin{equation}
\boxed{\theta=2\phi,\qquad \phi=\frac{\theta}{2}.}
\end{equation}

\subsection*{Solution 13: derive the quaternion exponential}

From the power series,
\[
\exp(\widehat{\mathbf u}\phi)
=\sum_{n=0}^{\infty}
\frac{(\widehat{\mathbf u}\phi)^n}{n!}.
\]
Because $\widehat{\mathbf u}^{\,2}=-1$, the even powers give the cosine series
and the odd powers give $\widehat{\mathbf u}$ times the sine series:
\begin{equation}
\boxed{
\exp(\widehat{\mathbf u}\phi)
=\cos\phi+\widehat{\mathbf u}\sin\phi.
}
\end{equation}
Setting $\phi=\theta/2$ gives the axis angle quaternion
\begin{equation}
\boxed{
q
=\exp\left(\frac{\theta}{2}\widehat{\mathbf u}\right).
}
\end{equation}

\subsection*{Solution 14: principal representative from a negative scalar part}

For the given quaternion,
\[
q_w=-0.9238795,
\qquad
\lVert\mathbf q\rVert=0.3826834.
\]
Using the quaternion exactly as supplied,
\begin{equation}
\theta
=2\operatorname{atan2}(0.3826834,-0.9238795)
\approx315^\circ.
\end{equation}
The vector part points along $-\widehat{\mathbf z}$, so this is a
$315^\circ$ rotation about $-\widehat{\mathbf z}$.

For a principal representation, first replace $q$ by $-q$:
\[
-q=(0.9238795,0,0,0.3826834).
\]
Now
\begin{equation}
\theta
=2\operatorname{atan2}(0.3826834,0.9238795)
\approx45^\circ,
\end{equation}
and the axis is $+\widehat{\mathbf z}$.  Therefore the principal pair is
\begin{equation}
\boxed{+45^\circ\text{ about }+\widehat{\mathbf z}.}
\end{equation}
A $315^\circ$ rotation about $-\widehat{\mathbf z}$ and a $45^\circ$ rotation
about $+\widehat{\mathbf z}$ have the same physical effect.  The two unit
quaternions differ only by sign.

\section{Sources and exercise provenance}

The problems and solutions above are newly written for PhysicsLibrary.  Their
subject matter is cross checked against public domain quaternion texts by
Hamilton, Hathaway, Joly, and Macfarlane.  In particular, Joly describes the
sandwich transformation as a rotation through twice the quaternion angle, and
Hathaway develops axis and finite rotation geometry before introducing
quaternions.  No historical exercise has been transcribed verbatim.

\begin{thebibliography}{9}

\bibitem{Joly1905}
C. J. Joly,
\emph{A Manual of Quaternions},
Macmillan and Co., London, 1905.
Public domain historical source.

\bibitem{Hathaway1896}
A. S. Hathaway,
\emph{A Primer of Quaternions}, 1896.
Public domain text; Project Gutenberg edition and \LaTeX{} source available.
\PMlinkexternal{Project Gutenberg edition}{https://www.gutenberg.org/ebooks/9934}

\bibitem{Macfarlane1906}
A. Macfarlane,
\emph{Vector Analysis and Quaternions},
John Wiley \&amp; Sons, New York, 1906.
Public domain historical source.
\PMlinkexternal{Project Gutenberg edition}{https://www.gutenberg.org/ebooks/13609}

\end{thebibliography}

\section*{License}

Unless otherwise noted, this PhysicsLibrary entry is intended for release under
the Creative Commons Attribution--ShareAlike 4.0 International license.</content>
</record>
