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 rotating vectors with quaternions (Example)

Rotating Vectors with Quaternions: Examples, Exercises, and Solutions

This entry is the self-study companion to the PhysicsLibrary article rotating vectors with quaternions. The convention throughout is Hamilton multiplication in a right-handed frame, with scalar-first quaternion display and active vector rotation

$\displaystyle \boxed{\mathbf v'=q\mathbf vq^*.}$ (1)
The quaternion is assumed to have unit norm unless a problem states otherwise.

Exercises

  1. Pure-quaternion representation. Write the vector

    $\displaystyle \mathbf v=2\hat{\mathbf x}-3\hat{\mathbf y}+4\hat{\mathbf z} $
    as a scalar-first pure quaternion.
  2. $+90^\circ$ about $+z$. Use quaternion multiplication to rotate

    $\displaystyle \mathbf v=\hat{\mathbf x} $
    through $+90^\circ$ about $+z$. Show every quaternion multiplication step.
  3. $+90^\circ$ about $+x$. Rotate

    $\displaystyle \mathbf v=\hat{\mathbf y} $
    through $+90^\circ$ about $+x$ and determine the resulting Cartesian vector.
  4. A vector parallel to the axis. Let

    $\displaystyle q=\cos 35^\circ+\mathbf k\sin35^\circ. $
    What physical rotation does $q$ represent? Apply it to $\mathbf v=5\mathbf k$ and explain the result geometrically.
  5. Rotation through $180^\circ$. Rotate

    $\displaystyle \mathbf v=2\mathbf i-3\mathbf j+4\mathbf k $
    through $180^\circ$ about $+z$.
  6. A symmetric $120^\circ$ rotation. Let

    $\displaystyle \widehat{\mathbf u}=\frac{\mathbf i+\mathbf j+\mathbf k}{\sqrt3}, \qquad \theta=120^\circ. $
    Construct $q$ and show that the active rotation sends

    $\displaystyle \mathbf i\longrightarrow\mathbf j. $
  7. Rodrigues formula. Using

    $\displaystyle \widehat{\mathbf u}=\mathbf k, \qquad \theta=60^\circ, \qquad \mathbf v=2\mathbf i+\mathbf j+3\mathbf k, $
    evaluate the rotated vector using Rodrigues' formula.
  8. Quaternion sign ambiguity. Prove directly that $q$ and $-q$ rotate every vector identically under the sandwich action.
  9. Inverse rotation. If

    $\displaystyle \mathbf v'=q\mathbf vq^*, $
    prove that

    $\displaystyle \mathbf v=q^*\mathbf v'q. $
  10. Norm preservation. Use quaternion norm multiplicativity to prove that a unit quaternion preserves the Euclidean magnitude of every rotated vector.
  11. Deriving Rodrigues' formula. Starting from

    $\displaystyle q=c+s\widehat{\mathbf u}, \qquad q^*=c-s\widehat{\mathbf u}, $
    derive

    $\displaystyle \mathbf v' =\mathbf v\cos\theta +(\widehat{\mathbf u}\times\mathb... ...n\theta +\widehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v)(1-\cos\theta). $
  12. Vector-only implementation. Show that, for a unit quaternion $q=(q_w,\mathbf q)$,

    $\displaystyle \mathbf v' =\mathbf v +2q_w(\mathbf q\times\mathbf v) +2\mathbf q\times(\mathbf q\times\mathbf v). $
    Then rewrite it using

    $\displaystyle \mathbf t=2(\mathbf q\times\mathbf v). $
  13. Active versus passive. A fixed physical vector has coordinates

    $\displaystyle \mathbf v_A=\hat{\mathbf x} $
    in frame $A$. Frame $B$ is obtained by rotating the coordinate axes $+90^\circ$ about $+z$ relative to $A$. Using the same unit quaternion that would actively rotate vectors by $+90^\circ$ about $+z$, determine the coordinates $\mathbf v_B$.
  14. Scalar-first and scalar-last software arrays. The quaternion for a $+90^\circ$ rotation about $+z$ is displayed in PhysicsLibrary scalar-first form as

    $\displaystyle \left[\frac{\sqrt2}{2},0,0,\frac{\sqrt2}{2}\right]^T. $
    Write the same quaternion in scalar-last storage. Explain whether the Hamilton multiplication law changes.
  15. Debugging the wrong sandwich order. A program intends to actively rotate $\hat{\mathbf x}$ by $+90^\circ$ about $+z$, but it computes

    $\displaystyle q^*\mathbf i q. $
    Predict the output and explain the error.
  16. Nonunit quaternion pitfall. Let

    $\displaystyle r=2q, $
    where $q$ is unit. Show that

    $\displaystyle r\mathbf v r^*=4q\mathbf vq^*. $
    Explain why a nonunit quaternion should not be used with the conjugate sandwich formula when a pure rotation is intended.

Solutions

1. Pure-quaternion representation

The scalar part is zero, so

$\displaystyle \boxed{ \mathbf v \longleftrightarrow \begin{bmatrix} 0&2&-3&4 \end{bmatrix}^{T}. }$ (2)

2. $+90^\circ$ about $+z$

The rotation quaternion is

$\displaystyle q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k, \qquad q^*=\frac{\sqrt2}{2}-\frac{\sqrt2}{2}\mathbf k. $
First,
\begin{equation*}\begin{aligned} q\mathbf i &=\frac{\sqrt2}{2}\mathbf i +\frac{\... ...thbf i \ &=\frac{\sqrt2}{2}(\mathbf i+\mathbf j). \end{aligned}\end{equation*}
Then
\begin{equation*}\begin{aligned} q\mathbf i q^* &=\frac12(\mathbf i+\mathbf j)(1... ...f i+\mathbf j+\mathbf j-\mathbf i) \ &=\mathbf j. \end{aligned}\end{equation*}
Therefore
$\displaystyle \boxed{\hat{\mathbf x}\rightarrow\hat{\mathbf y}.}$ (5)

3. $+90^\circ$ about $+x$

By the right-hand rule, a positive quarter-turn about $+x$ carries $+y$ toward $+z$. Thus

$\displaystyle \boxed{\hat{\mathbf y}\rightarrow\hat{\mathbf z}.}$ (6)
The quaternion is

$\displaystyle q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf i. $
Direct multiplication gives the same result.

4. Vector parallel to the axis

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

$\displaystyle \theta=70^\circ. $
The axis is $+z$. Since $\mathbf v=5\mathbf k$ is parallel to the axis,
$\displaystyle \boxed{q(5\mathbf k)q^*=5\mathbf k.}$ (7)
A rotation leaves every vector on its own axis unchanged.

5. Rotation through $180^\circ$

A $180^\circ$ rotation about $+z$ reverses the $x$ and $y$ components and leaves the $z$ component unchanged. Therefore

$\displaystyle \boxed{ \mathbf v'=-2\mathbf i+3\mathbf j+4\mathbf k. }$ (8)

6. Symmetric $120^\circ$ rotation

Since

$\displaystyle \cos60^\circ=\frac12, \qquad \sin60^\circ=\frac{\sqrt3}{2}, $
we obtain
$\displaystyle \boxed{ q=\frac12(1+\mathbf i+\mathbf j+\mathbf k). }$ (9)
Using Rodrigues' formula with $\widehat{\mathbf u}=(1,1,1)/\sqrt3$ and $\mathbf v=\mathbf i$ gives
$\displaystyle \boxed{\mathbf v'=\mathbf j.}$ (10)
Thus this $120^\circ$ rotation cyclically carries the coordinate axes $x\rightarrow y\rightarrow z\rightarrow x$.

7. Rodrigues formula

For $\widehat{\mathbf u}=\mathbf k$,

$\displaystyle \widehat{\mathbf u}\times\mathbf v =\mathbf k\times(2\mathbf i+\mathbf j+3\mathbf k) =2\mathbf j-\mathbf i, $
and

$\displaystyle \widehat{\mathbf u}\cdot\mathbf v=3. $
With $\cos60^\circ=1/2$ and $\sin60^\circ=\sqrt3/2$,
\begin{equation*}\begin{aligned} \mathbf v' ={}&\frac12(2\mathbf i+\mathbf j+3\m... ... +\left(\frac12+\sqrt3\right)\mathbf j +3\mathbf k. \end{aligned}\end{equation*}
Hence
$\displaystyle \boxed{ \mathbf v' =\left(1-\frac{\sqrt3}{2}\right)\mathbf i +\left(\frac12+\sqrt3\right)\mathbf j +3\mathbf k. }$ (12)

8. Quaternion sign ambiguity

Because $(-q)^*=-q^*$,

$\displaystyle (-q)\mathbf v(-q)^* =(-q)\mathbf v(-q^*) =q\mathbf vq^*.$ (13)
Therefore
$\displaystyle \boxed{q\text{ and }-q\text{ generate the same vector rotation}.}$ (14)

9. Inverse rotation

Start with

$\displaystyle \mathbf v'=q\mathbf vq^*. $
Multiply on the left by $q^*$ and on the right by $q$:
\begin{equation*}\begin{aligned} q^*\mathbf v'q &=q^*(q\mathbf vq^*)q \ &=(q^*q)\mathbf v(q^*q) \ &=\mathbf v. \end{aligned}\end{equation*}
Thus
$\displaystyle \boxed{\mathbf v=q^*\mathbf v'q.}$ (16)

10. Norm preservation

For unit $q$,

$\displaystyle \lVert q\rVert=\lVert q^*\rVert=1. $
Hence
\begin{equation*}\begin{aligned} \lVert\mathbf v'\rVert &=\lVert q\mathbf vq^*\r... ...Vert\,\lVert q^*\rVert \ &=\lVert\mathbf v\rVert. \end{aligned}\end{equation*}
So quaternion conjugation by a unit quaternion preserves Euclidean vector length.

11. Deriving Rodrigues' formula

Let

$\displaystyle q=c+s\widehat{\mathbf u}. $
The first product is
$\displaystyle q\mathbf v = \left( -s\widehat{\mathbf u}\cdot\mathbf v, \;c\mathbf v+s\widehat{\mathbf u}\times\mathbf v \right).$ (18)
Multiplication by $q^*=(c,-s\widehat{\mathbf u})$ cancels the scalar part and gives
\begin{equation*}\begin{aligned} \mathbf v' ={}&(c^2-s^2)\mathbf v +2cs(\widehat... ...ehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v). \end{aligned}\end{equation*}
Using

$\displaystyle c^2-s^2=\cos\theta, \qquad 2cs=\sin\theta, \qquad 2s^2=1-\cos\theta, $
produces
$\displaystyle \boxed{ \mathbf v' =\mathbf v\cos\theta +(\widehat{\mathbf u}\tim... ...\theta +\widehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v)(1-\cos\theta). }$ (20)

12. Vector-only implementation

Write $q=(q_w,\mathbf q)$. Expanding the sandwich product and collecting cross-product terms gives

$\displaystyle \boxed{ \mathbf v' =\mathbf v +2q_w(\mathbf q\times\mathbf v) +2\mathbf q\times(\mathbf q\times\mathbf v). }$ (21)
If
$\displaystyle \mathbf t=2(\mathbf q\times\mathbf v),$ (22)
then
$\displaystyle \boxed{ \mathbf v'=\mathbf v+q_w\mathbf t+\mathbf q\times\mathbf t. }$ (23)

13. Active versus passive

The active quaternion for $+90^\circ$ about $+z$ is

$\displaystyle q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k. $
A passive coordinate change uses the inverse action,

$\displaystyle \mathbf v_B=q^*\mathbf v_Aq. $
For $\mathbf v_A=\mathbf i$,
$\displaystyle \boxed{\mathbf v_B=-\mathbf j.}$ (24)
Therefore the fixed vector has coordinates
$\displaystyle \boxed{ [0,-1,0]^T }$ (25)
in the rotated frame.

14. Scalar-first and scalar-last arrays

Scalar-first storage is

$\displaystyle \left[\frac{\sqrt2}{2},0,0,\frac{\sqrt2}{2}\right]^T. $
Scalar-last storage places the scalar at the end:
$\displaystyle \boxed{ \left[0,0,\frac{\sqrt2}{2},\frac{\sqrt2}{2}\right]^T. }$ (26)
The Hamilton multiplication law does not change. Only the array indexing changes.

15. Debugging the wrong sandwich order

The expression

$\displaystyle q^*\mathbf i q $
applies the inverse rotation. Therefore the output is
$\displaystyle \boxed{-\mathbf j.}$ (27)
The intended active formula was $q\mathbf i q^*$.

16. Nonunit quaternion pitfall

With $r=2q$,

$\displaystyle r^*=2q^*. $
Therefore
$\displaystyle r\mathbf vr^* =(2q)\mathbf v(2q^*) =4q\mathbf vq^*.$ (28)
Thus
$\displaystyle \boxed{ \lVert r\mathbf vr^*\rVert=4\lVert\mathbf v\rVert. }$ (29)
The conjugate sandwich formula represents a pure rotation only when the orientation quaternion is unit. A nonunit quaternion should be normalized, or the true inverse should be used if a general quaternion similarity transform is intended.

Sources

The rotation law is cross-checked against the public-domain treatments of Joly and Hathaway, both of which use the classical rotator $q(\cdot)q^{-1}$. The problems and worked solutions here are newly written for PhysicsLibrary.

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

License

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



"example of rotating vectors with quaternions" is owned by bloftin.
(view preamble)
View style:
Keywords:  quaternion, vector rotation, unit quaternion, Rodrigues formula, pure quaternion, active rotation, passive rotation, exercises, worked solutions

This object's parent.

Cross-references: conjugation, scalar, program, magnitude, quaternion norm, formula, quaternion multiplication, representation, norm, vector, quaternion, rotating vectors with quaternions

This is version 1 of example of rotating vectors with quaternions, born on 2026-08-23.
Object id is 1098, canonical name is ExampleOfRotatingVectorsWithQuaternions.
Accessed 6 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)