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 Axis Angle Representation and Unit Quaternion (Example)

Axis Angle Representation and Unit Quaternion: Examples, Exercises, and Solutions

This companion entry is designed for self study after the PhysicsLibrary article 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

$\displaystyle \boxed{ q =\cos\frac{\theta}{2} +\widehat{\mathbf u}\sin\frac{\theta}{2}. }$ (1)
Angles are positive according to the right-hand rule about $\widehat{\mathbf u}$.

Exercises

Foundational exercises

  1. $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.
  2. $120^\circ$ about the $(1,1,1)$ axis. Construct the quaternion for a positive active rotation of $120^\circ$ about

    $\displaystyle \widehat{\mathbf u}=\frac{1}{\sqrt3}(1,1,1). $
    Verify directly that the quaternion has unit norm.
  3. A nontrivial normalized axis. Construct the quaternion for a rotation of $60^\circ$ about the axis

    $\displaystyle \widehat{\mathbf u}=\frac13(1,2,2). $
    Write the exact scalar-first components.
  4. Recover an axis and angle. For

    $\displaystyle q=\left(\frac{\sqrt2}{2},\;0,\;\frac{\sqrt2}{2},\;0\right), $
    recover the principal axis and angle.
  5. A $180^\circ$ quaternion. For the unit quaternion

    $\displaystyle q=\left(0,\;\frac13,\;-\frac23,\;\frac23\right), $
    find the axis and angle. Explain what happens if the quaternion is replaced by $-q$.

Convention and interpretation exercises

  1. The $q$ versus $-q$ ambiguity. Let

    $\displaystyle 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.
  2. 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?
  3. 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.
  4. 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

    $\displaystyle 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.

Engineering and derivation exercises

  1. Small attitude correction. An attitude estimator produces the small rotation vector

    $\displaystyle \delta\boldsymbol\theta =\begin{bmatrix}0.01&-0.02&0.03\end{bmatrix}^{T}\ $   rad$\displaystyle . $
    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.
  2. Engineering command axis. A spacecraft is commanded to rotate by $15^\circ$ about the body fixed unit axis

    $\displaystyle \widehat{\mathbf u}=\frac13(2,-1,2). $
    Construct the exact command quaternion and give numerical component values to at least six significant digits.
  3. Derive the half angle. Let $\widehat{\mathbf u}$ and $\mathbf v$ be perpendicular unit pure quaternions and let

    $\displaystyle 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$.
  4. Derive the quaternion exponential. Using only $\widehat{\mathbf u}^{\,2}=-1$ and the power series definition of the exponential, prove

    $\displaystyle \exp(\widehat{\mathbf u}\phi) =\cos\phi+\widehat{\mathbf u}\sin\phi. $
    Then write the axis angle quaternion as an exponential.
  5. Principal representative from a negative scalar part. A normalized attitude quaternion is received as

    $\displaystyle 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.

Solutions

Solution 1: $90^\circ$ about the $z$ axis

Here

$\displaystyle \widehat{\mathbf u}=\mathbf k, \qquad \frac{\theta}{2}=45^\circ. $
Therefore
$\displaystyle \boxed{ q =\cos45^\circ+\mathbf k\sin45^\circ =\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k. }$ (2)
In scalar-first column form,
$\displaystyle \boxed{ q= \begin{bmatrix} \sqrt2/2\\ 0\\ 0\\ \sqrt2/2 \end{bmatrix}. }$ (3)

Solution 2: $120^\circ$ about $(1,1,1)$

The half angle is $60^\circ$, so

$\displaystyle \cos60^\circ=\frac12, \qquad \sin60^\circ=\frac{\sqrt3}{2}. $
Multiplying the sine by the axis gives

$\displaystyle \frac{\sqrt3}{2} \frac1{\sqrt3}(1,1,1) =\frac12(1,1,1). $
Thus
$\displaystyle \boxed{ q=\frac12 +\frac12\mathbf i +\frac12\mathbf j +\frac12\mathbf k. }$ (4)
Its squared norm is

$\displaystyle \lVert q\rVert^2 =\frac14+\frac14+\frac14+\frac14=1. $

Solution 3: $60^\circ$ about $(1,2,2)/3$

The axis is already unit because

$\displaystyle \frac{1^2+2^2+2^2}{3^2}=1. $
The half angle is $30^\circ$, with

$\displaystyle \cos30^\circ=\frac{\sqrt3}{2}, \qquad \sin30^\circ=\frac12. $
Therefore
$\displaystyle \boxed{ q =\frac{\sqrt3}{2} +\frac16\mathbf i +\frac13\mathbf j +\frac13\mathbf k. }$ (5)

Solution 4: recover an axis and angle

The scalar part is

$\displaystyle q_w=\frac{\sqrt2}{2}, $
and the vector part magnitude is

$\displaystyle s=\frac{\sqrt2}{2}. $
Hence
$\displaystyle \theta =2\operatorname{atan2}\left(\frac{\sqrt2}{2},\frac{\sqrt2}{2}\right) =2\left(\frac{\pi}{4}\right) =\frac{\pi}{2}.$ (6)
The axis is

$\displaystyle \widehat{\mathbf u} =\frac{(0,\sqrt2/2,0)}{\sqrt2/2} =(0,1,0). $
Thus the rotation is

$\displaystyle \boxed{+90^\circ\text{ about }+\widehat{\mathbf y}.} $

Solution 5: a $180^\circ$ quaternion

Here $q_w=0$ and the vector part already has unit magnitude. Therefore

$\displaystyle \theta=2\operatorname{atan2}(1,0)=\pi.$ (7)
The axis is
$\displaystyle \boxed{ \widehat{\mathbf u} =\frac13(1,-2,2). }$ (8)
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.

Solution 6: $q$ versus $-q$

The quaternion phase is $20^\circ$, so the physical angle is

$\displaystyle \theta=40^\circ, $
about $+\widehat{\mathbf z}$.

For the negative quaternion,

$\displaystyle -q=-\cos20^\circ-\mathbf k\sin20^\circ. $
Using an angle in $[0,2\pi]$,

$\displaystyle -\cos20^\circ=\cos160^\circ, \qquad -\sin20^\circ=-\sin160^\circ. $
Thus
$\displaystyle -q =\cos160^\circ -\mathbf k\sin160^\circ.$ (9)
Its physical axis angle pair can therefore be written as

$\displaystyle \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}$.

Solution 7: zero, $2\pi$, and $4\pi$

For a fixed axis,

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

Solution 8: active inverse and passive counterpart

The positive active quaternion is

$\displaystyle \boxed{ q=\cos15^\circ+\mathbf k\sin15^\circ. }$ (11)
Because it is unit,
$\displaystyle \boxed{ q^{-1}=q^* =\cos15^\circ-\mathbf k\sin15^\circ. }$ (12)
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.

Solution 9: the nonunit axis trap

The programmer uses

$\displaystyle \mathbf u=2\mathbf i, \qquad \frac{\theta}{2}=45^\circ. $
This gives
$\displaystyle q_{\rm bad} =\frac{\sqrt2}{2}+\sqrt2\,\mathbf i.$ (13)
Its squared norm is

$\displaystyle \lVert q_{\rm bad}\rVert^2 =\frac12+2=\frac52, $
so
$\displaystyle \boxed{\lVert q_{\rm bad}\rVert=\sqrt{\frac52}\neq1.}$ (14)
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
$\displaystyle \boxed{ q =\frac{\sqrt2}{2} +\frac{\sqrt2}{2}\mathbf i. }$ (15)

Solution 10: small attitude correction

The first order approximation is

$\displaystyle q\approx \begin{bmatrix} 1\ \tfrac12(0.01)\ \tfrac12(-0.02)\\... ...(0.03) \end{bmatrix}=\begin{bmatrix} 1\\ 0.005\\ -0.010\\ 0.015 \end{bmatrix}. $
Its squared norm is

$\displaystyle 1+0.005^2+0.010^2+0.015^2 =1.00035, $
so
$\displaystyle \boxed{ \lVert q\rVert=\sqrt{1.00035}\approx1.000174985. }$ (16)
Normalizing gives approximately
$\displaystyle \boxed{ \widehat q \approx \begin{bmatrix} 0.99982505\ 0.00499913\ -0.00999825\ 0.01499738 \end{bmatrix}. }$ (17)
The norm error is second order, as expected from a first order small angle approximation.

Solution 11: engineering command axis

The half angle is

$\displaystyle \frac{\theta}{2}=7.5^\circ. $
Thus
$\displaystyle q =\cos7.5^\circ +\frac13(2\mathbf i-\mathbf j+2\mathbf k)\sin7.5^\circ.$ (18)
Using

$\displaystyle \cos7.5^\circ\approx0.991444861, \qquad \sin7.5^\circ\approx0.130526192, $
we obtain
$\displaystyle \boxed{ q\approx \begin{bmatrix} 0.991444861\ 0.087017461\ -0.043508731\ 0.087017461 \end{bmatrix}. }$ (19)

Solution 12: derive the half angle

Let

$\displaystyle c=\cos\phi, \qquad s=\sin\phi, \qquad q=c+s\widehat{\mathbf u}. $
Because $q$ is unit,

$\displaystyle q^*=c-s\widehat{\mathbf u}. $
For perpendicular unit pure quaternions,

$\displaystyle \widehat{\mathbf u}\mathbf v =\widehat{\mathbf u}\times\mathbf v,... ...es\mathbf v, \qquad \widehat{\mathbf u}\mathbf v\widehat{\mathbf u}=\mathbf v. $
Therefore
\begin{equation*}\begin{aligned} q\mathbf vq^* &=(c+s\widehat{\mathbf u})\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
$\displaystyle \boxed{\theta=2\phi,\qquad \phi=\frac{\theta}{2}.}$ (21)

Solution 13: derive the quaternion exponential

From the power series,

$\displaystyle \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:
$\displaystyle \boxed{ \exp(\widehat{\mathbf u}\phi) =\cos\phi+\widehat{\mathbf u}\sin\phi. }$ (22)
Setting $\phi=\theta/2$ gives the axis angle quaternion
$\displaystyle \boxed{ q =\exp\left(\frac{\theta}{2}\widehat{\mathbf u}\right). }$ (23)

Solution 14: principal representative from a negative scalar part

For the given quaternion,

$\displaystyle q_w=-0.9238795, \qquad \lVert\mathbf q\rVert=0.3826834. $
Using the quaternion exactly as supplied,
$\displaystyle \theta =2\operatorname{atan2}(0.3826834,-0.9238795) \approx315^\circ.$ (24)
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$:

$\displaystyle -q=(0.9238795,0,0,0.3826834). $
Now
$\displaystyle \theta =2\operatorname{atan2}(0.3826834,0.9238795) \approx45^\circ,$ (25)
and the axis is $+\widehat{\mathbf z}$. Therefore the principal pair is
$\displaystyle \boxed{+45^\circ\text{ about }+\widehat{\mathbf z}.}$ (26)
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.

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.

Bibliography

1
C. J. Joly, A Manual of Quaternions, Macmillan and Co., London, 1905. Public domain historical source.
2
A. S. Hathaway, A Primer of Quaternions, 1896. Public domain text; Project Gutenberg edition and LATEX source available. Project Gutenberg edition
3
A. Macfarlane, Vector Analysis and Quaternions, John Wiley & Sons, New York, 1906. Public domain historical source. Project Gutenberg edition

License

Unless otherwise noted, this PhysicsLibrary entry is intended for release under the Creative Commons Attribution–ShareAlike 4.0 International license.



"example of Axis Angle Representation and Unit Quaternion" is owned by bloftin.
(view preamble)
View style:

This object's parent.

Cross-references: domain, representation, powers, relation, magnitude, scalar, power series, vector, norm, quaternion, section, work, Axis Angle Representation and Unit Quaternion

This is version 1 of example of Axis Angle Representation and Unit Quaternion, born on 2026-08-23.
Object id is 1096, canonical name is ExampleOfAxisAngleRepresentationAndUnitQuaternion.
Accessed 10 times total.

Classification:
Physics Classification02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)
Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:

No messages.

Interact
rate | post | correct | update request | add example | add (any)