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

<record version="1" id="1098">
 <title>example of rotating vectors with quaternions</title>
 <name>ExampleOfRotatingVectorsWithQuaternions</name>
 <created>2026-08-23 20:49:30</created>
 <modified>2026-08-23 20:49:30</modified>
 <type>Example</type>
<parent id="1097">rotating vectors with quaternions</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>
 <keywords>
	<term>quaternion</term>
	<term>vector rotation</term>
	<term>unit quaternion</term>
	<term>Rodrigues formula</term>
	<term>pure quaternion</term>
	<term>active rotation</term>
	<term>passive rotation</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)
%\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*{Rotating Vectors with Quaternions: Examples, Exercises, and Solutions}

This entry is the self-study companion to the PhysicsLibrary article
\emph{Rotating Vectors with Quaternions}.  The convention throughout is
Hamilton multiplication in a right-handed frame, with scalar-first quaternion
display and active vector rotation
\begin{equation}
\boxed{\mathbf v'=q\mathbf vq^*.}
\end{equation}
The quaternion is assumed to have unit norm unless a problem states otherwise.

\section{Exercises}

\begin{enumerate}

\item \textbf{Pure-quaternion representation.}
Write the vector
\[
\mathbf v=2\hat{\mathbf x}-3\hat{\mathbf y}+4\hat{\mathbf z}
\]
as a scalar-first pure quaternion.

\item \textbf{$+90^\circ$ about $+z$.}
Use quaternion multiplication to rotate
\[
\mathbf v=\hat{\mathbf x}
\]
through $+90^\circ$ about $+z$.  Show every quaternion multiplication step.

\item \textbf{$+90^\circ$ about $+x$.}
Rotate
\[
\mathbf v=\hat{\mathbf y}
\]
through $+90^\circ$ about $+x$ and determine the resulting Cartesian vector.

\item \textbf{A vector parallel to the axis.}
Let
\[
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.

\item \textbf{Rotation through $180^\circ$.}
Rotate
\[
\mathbf v=2\mathbf i-3\mathbf j+4\mathbf k
\]
through $180^\circ$ about $+z$.

\item \textbf{A symmetric $120^\circ$ rotation.}
Let
\[
\widehat{\mathbf u}=\frac{\mathbf i+\mathbf j+\mathbf k}{\sqrt3},
\qquad
\theta=120^\circ.
\]
Construct $q$ and show that the active rotation sends
\[
\mathbf i\longrightarrow\mathbf j.
\]

\item \textbf{Rodrigues formula.}
Using
\[
\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.

\item \textbf{Quaternion sign ambiguity.}
Prove directly that $q$ and $-q$ rotate every vector identically under the
sandwich action.

\item \textbf{Inverse rotation.}
If
\[
\mathbf v'=q\mathbf vq^*,
\]
prove that
\[
\mathbf v=q^*\mathbf v'q.
\]

\item \textbf{Norm preservation.}
Use quaternion norm multiplicativity to prove that a unit quaternion preserves
the Euclidean magnitude of every rotated vector.

\item \textbf{Deriving Rodrigues' formula.}
Starting from
\[
q=c+s\widehat{\mathbf u},
\qquad
q^*=c-s\widehat{\mathbf u},
\]
derive
\[
\mathbf v'
=\mathbf v\cos\theta
+(\widehat{\mathbf u}\times\mathbf v)\sin\theta
+\widehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v)(1-\cos\theta).
\]

\item \textbf{Vector-only implementation.}
Show that, for a unit quaternion $q=(q_w,\mathbf q)$,
\[
\mathbf v'
=\mathbf v
+2q_w(\mathbf q\times\mathbf v)
+2\mathbf q\times(\mathbf q\times\mathbf v).
\]
Then rewrite it using
\[
\mathbf t=2(\mathbf q\times\mathbf v).
\]

\item \textbf{Active versus passive.}
A fixed physical vector has coordinates
\[
\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$.

\item \textbf{Scalar-first and scalar-last software arrays.}
The quaternion for a $+90^\circ$ rotation about $+z$ is displayed in
PhysicsLibrary scalar-first form as
\[
\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.

\item \textbf{Debugging the wrong sandwich order.}
A program intends to actively rotate $\hat{\mathbf x}$ by $+90^\circ$ about
$+z$, but it computes
\[
q^*\mathbf i q.
\]
Predict the output and explain the error.

\item \textbf{Nonunit quaternion pitfall.}
Let
\[
r=2q,
\]
where $q$ is unit.  Show that
\[
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.

\end{enumerate}

\section{Solutions}

\subsection*{1. Pure-quaternion representation}

The scalar part is zero, so
\begin{equation}
\boxed{
\mathbf v
\longleftrightarrow
\begin{bmatrix}
0&amp;2&amp;-3&amp;4
\end{bmatrix}^{T}.
}
\end{equation}

\subsection*{2. $+90^\circ$ about $+z$}

The rotation quaternion is
\[
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
&amp;=\frac{\sqrt2}{2}\mathbf i
+\frac{\sqrt2}{2}\mathbf k\mathbf i \\
&amp;=\frac{\sqrt2}{2}(\mathbf i+\mathbf j).
\end{aligned}
\end{equation}
Then
\begin{equation}
\begin{aligned}
q\mathbf i q^*
&amp;=\frac12(\mathbf i+\mathbf j)(1-\mathbf k) \\
&amp;=\frac12(\mathbf i+\mathbf j-\mathbf i\mathbf k-\mathbf j\mathbf k) \\
&amp;=\frac12(\mathbf i+\mathbf j+\mathbf j-\mathbf i) \\
&amp;=\mathbf j.
\end{aligned}
\end{equation}
Therefore
\begin{equation}
\boxed{\hat{\mathbf x}\rightarrow\hat{\mathbf y}.}
\end{equation}

\subsection*{3. $+90^\circ$ about $+x$}

By the right-hand rule, a positive quarter-turn about $+x$ carries $+y$ toward
$+z$.  Thus
\begin{equation}
\boxed{\hat{\mathbf y}\rightarrow\hat{\mathbf z}.}
\end{equation}
The quaternion is
\[
q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf i.
\]
Direct multiplication gives the same result.

\subsection*{4. Vector parallel to the axis}

The quaternion phase is $35^\circ$, so the physical rotation angle is
\[
\theta=70^\circ.
\]
The axis is $+z$.  Since $\mathbf v=5\mathbf k$ is parallel to the axis,
\begin{equation}
\boxed{q(5\mathbf k)q^*=5\mathbf k.}
\end{equation}
A rotation leaves every vector on its own axis unchanged.

\subsection*{5. Rotation through $180^\circ$}

A $180^\circ$ rotation about $+z$ reverses the $x$ and $y$ components and
leaves the $z$ component unchanged.  Therefore
\begin{equation}
\boxed{
\mathbf v'=-2\mathbf i+3\mathbf j+4\mathbf k.
}
\end{equation}

\subsection*{6. Symmetric $120^\circ$ rotation}

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

\subsection*{7. Rodrigues formula}

For $\widehat{\mathbf u}=\mathbf k$,
\[
\widehat{\mathbf u}\times\mathbf v
=\mathbf k\times(2\mathbf i+\mathbf j+3\mathbf k)
=2\mathbf j-\mathbf i,
\]
and
\[
\widehat{\mathbf u}\cdot\mathbf v=3.
\]
With $\cos60^\circ=1/2$ and $\sin60^\circ=\sqrt3/2$,
\begin{equation}
\begin{aligned}
\mathbf v'
={}&amp;\frac12(2\mathbf i+\mathbf j+3\mathbf k)
+\frac{\sqrt3}{2}(2\mathbf j-\mathbf i)
+\frac32\mathbf k \\
={}&amp;\left(1-\frac{\sqrt3}{2}\right)\mathbf i
+\left(\frac12+\sqrt3\right)\mathbf j
+3\mathbf k.
\end{aligned}
\end{equation}
Hence
\begin{equation}
\boxed{
\mathbf v'
=\left(1-\frac{\sqrt3}{2}\right)\mathbf i
+\left(\frac12+\sqrt3\right)\mathbf j
+3\mathbf k.
}
\end{equation}

\subsection*{8. Quaternion sign ambiguity}

Because $(-q)^*=-q^*$,
\begin{equation}
(-q)\mathbf v(-q)^*
=(-q)\mathbf v(-q^*)
=q\mathbf vq^*.
\end{equation}
Therefore
\begin{equation}
\boxed{q\text{ and }-q\text{ generate the same vector rotation}.}
\end{equation}

\subsection*{9. Inverse rotation}

Start with
\[
\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
&amp;=q^*(q\mathbf vq^*)q \\
&amp;=(q^*q)\mathbf v(q^*q) \\
&amp;=\mathbf v.
\end{aligned}
\end{equation}
Thus
\begin{equation}
\boxed{\mathbf v=q^*\mathbf v'q.}
\end{equation}

\subsection*{10. Norm preservation}

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

\subsection*{11. Deriving Rodrigues' formula}

Let
\[
q=c+s\widehat{\mathbf u}.
\]
The first product is
\begin{equation}
q\mathbf v
=
\left(
-s\widehat{\mathbf u}\cdot\mathbf v,
\;c\mathbf v+s\widehat{\mathbf u}\times\mathbf v
\right).
\end{equation}
Multiplication by $q^*=(c,-s\widehat{\mathbf u})$ cancels the scalar part and
gives
\begin{equation}
\begin{aligned}
\mathbf v'
={}&amp;(c^2-s^2)\mathbf v
+2cs(\widehat{\mathbf u}\times\mathbf v) \\
&amp;+2s^2\widehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v).
\end{aligned}
\end{equation}
Using
\[
c^2-s^2=\cos\theta,
\qquad
2cs=\sin\theta,
\qquad
2s^2=1-\cos\theta,
\]
produces
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v\cos\theta
+(\widehat{\mathbf u}\times\mathbf v)\sin\theta
+\widehat{\mathbf u}(\widehat{\mathbf u}\cdot\mathbf v)(1-\cos\theta).
}
\end{equation}

\subsection*{12. Vector-only implementation}

Write $q=(q_w,\mathbf q)$.  Expanding the sandwich product and collecting
cross-product terms gives
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v
+2q_w(\mathbf q\times\mathbf v)
+2\mathbf q\times(\mathbf q\times\mathbf v).
}
\end{equation}
If
\begin{equation}
\mathbf t=2(\mathbf q\times\mathbf v),
\end{equation}
then
\begin{equation}
\boxed{
\mathbf v'=\mathbf v+q_w\mathbf t+\mathbf q\times\mathbf t.
}
\end{equation}

\subsection*{13. Active versus passive}

The active quaternion for $+90^\circ$ about $+z$ is
\[
q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k.
\]
A passive coordinate change uses the inverse action,
\[
\mathbf v_B=q^*\mathbf v_Aq.
\]
For $\mathbf v_A=\mathbf i$,
\begin{equation}
\boxed{\mathbf v_B=-\mathbf j.}
\end{equation}
Therefore the fixed vector has coordinates
\begin{equation}
\boxed{
[0,-1,0]^T
}
\end{equation}
in the rotated frame.

\subsection*{14. Scalar-first and scalar-last arrays}

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

\subsection*{15. Debugging the wrong sandwich order}

The expression
\[
q^*\mathbf i q
\]
applies the inverse rotation.  Therefore the output is
\begin{equation}
\boxed{-\mathbf j.}
\end{equation}
The intended active formula was $q\mathbf i q^*$.

\subsection*{16. Nonunit quaternion pitfall}

With $r=2q$,
\[
r^*=2q^*.
\]
Therefore
\begin{equation}
r\mathbf vr^*
=(2q)\mathbf v(2q^*)
=4q\mathbf vq^*.
\end{equation}
Thus
\begin{equation}
\boxed{
\lVert r\mathbf vr^*\rVert=4\lVert\mathbf v\rVert.
}
\end{equation}
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.

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

\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}

\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>
