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

<record version="1" id="1097">
 <title>rotating vectors with quaternions</title>
 <name>RotatingVectorsWithQuaternions</name>
 <created>2026-08-23 20:47:19</created>
 <modified>2026-08-23 20:47:19</modified>
 <type>Topic</type>
 <creator id="1" name="bloftin"/>
 <modifier id="1" name="bloftin"/>
 <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>rigid-body attitude</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}

A unit quaternion can act directly on an ordinary three-dimensional vector.
The vector is first regarded as a pure quaternion, the unit quaternion is
applied on one side, and its conjugate is applied on the other.  For the
PhysicsLibrary convention, the active rotation law is
\begin{equation}
\boxed{
\mathbf v' = q\,\mathbf v\,q^*.
}
\end{equation}
Here $q$ is a unit quaternion, $\mathbf v$ is a pure quaternion representing a
three-dimensional vector, and $\mathbf v'$ is the rotated vector.

This compact formula is useful because the same quaternion can rotate any
vector without introducing Euler angles.  It also preserves vector length and
is equivalent to the familiar Rodrigues rotation formula.

\section{Convention declaration}

This entry uses Hamilton multiplication in a right-handed Cartesian frame:
\[
\mathbf i\mathbf j=\mathbf k,
\qquad
\mathbf j\mathbf k=\mathbf i,
\qquad
\mathbf k\mathbf i=\mathbf j.
\]
Positive rotation follows the right-hand screw rule.  Quaternion components are
displayed scalar first,
\begin{equation}
q=q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k
\quad\longleftrightarrow\quad
\begin{bmatrix}
q_w&amp;q_x&amp;q_y&amp;q_z
\end{bmatrix}^{T}.
\end{equation}
Scalar-last arrays such as
\[
[q_x,q_y,q_z,q_w]^T
\]
are also common in software.  They change only the storage order.  They do not
change Hamilton multiplication or the physical rotation represented by $q$.

For a rotation through angle $\theta$ about the unit axis
$\widehat{\mathbf u}$, the unit quaternion is
\begin{equation}
\boxed{
q
=\cos\frac{\theta}{2}
+\widehat{\mathbf u}\sin\frac{\theta}{2}.
}
\end{equation}
Because $\lVert q\rVert=1$,
\begin{equation}
q^{-1}=q^*.
\end{equation}

\section{Representing a vector as a pure quaternion}

Let the ordinary vector be
\[
\mathbf v=
\begin{bmatrix}
v_x&amp;v_y&amp;v_z
\end{bmatrix}^{T}.
\]
In quaternion algebra it is represented by the pure quaternion
\begin{equation}
\boxed{
\mathbf v
=v_x\mathbf i+v_y\mathbf j+v_z\mathbf k,
}
\end{equation}
whose scalar part is zero.  In scalar-first component form this is
\begin{equation}
\mathbf v
\quad\longleftrightarrow\quad
\begin{bmatrix}
0&amp;v_x&amp;v_y&amp;v_z
\end{bmatrix}^{T}.
\end{equation}
The same geometric vector remains three-dimensional.  The leading zero is only
needed when the vector is inserted into quaternion multiplication.

\section{The quaternion sandwich action}

Let
\begin{equation}
q=c+s\widehat{\mathbf u},
\qquad
c=\cos\frac{\theta}{2},
\qquad
s=\sin\frac{\theta}{2}.
\end{equation}
Then
\begin{equation}
q^*=c-s\widehat{\mathbf u}.
\end{equation}
The active rotation is
\begin{equation}
\mathbf v'
=(c+s\widehat{\mathbf u})\,\mathbf v\,(c-s\widehat{\mathbf u}).
\end{equation}
The expression is sometimes called a \emph{sandwich product} because the
vector appears between $q$ and $q^*$.

Figure~\ref{fig:q07-vector-rotation} shows the geometry.  The component of the
vector parallel to the rotation axis remains fixed, while the perpendicular
component moves around the axis through angle $\theta$.

\begin{figure}[h]
\centering
\includegraphics[width=0.78\textwidth]{Q07_quaternion_vector_rotation.png}
\caption{Quaternion rotation of a vector about the unit axis
$\widehat{\mathbf u}$.  The parallel component $\mathbf v_{\parallel}$ is
unchanged.  The perpendicular component rotates through $\theta$, carrying
$\mathbf v$ to $\mathbf v'$.}
\label{fig:q07-vector-rotation}
\end{figure}

\section{Derivation using scalar and vector parts}

The scalar--vector form of the Hamilton product is
\begin{equation}
(a,\mathbf a)(b,\mathbf b)
=
\left(
 ab-\mathbf a\cdot\mathbf b,
\;a\mathbf b+b\mathbf a+\mathbf a\times\mathbf b
\right).
\end{equation}
Write
\[
q=(c,s\widehat{\mathbf u}),
\qquad
\mathbf v=(0,\mathbf v).
\]
The first multiplication gives
\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}
Multiplying this result by
\[
q^*=(c,-s\widehat{\mathbf u})
\]
causes the scalar part to cancel.  The result is again a pure quaternion, so a
three-dimensional vector has been mapped to another three-dimensional vector.
The vector part becomes
\begin{equation}
\begin{aligned}
\mathbf v'
={}&amp;(c^2-s^2)\mathbf v
+2cs\left(\widehat{\mathbf u}\times\mathbf v\right) \\
&amp;+2s^2\widehat{\mathbf u}
\left(\widehat{\mathbf u}\cdot\mathbf v\right).
\end{aligned}
\end{equation}
Using the half-angle identities
\begin{equation}
c^2-s^2=\cos\theta,
\qquad
2cs=\sin\theta,
\qquad
2s^2=1-\cos\theta,
\end{equation}
we obtain
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v\cos\theta
+\left(\widehat{\mathbf u}\times\mathbf v\right)\sin\theta
+\widehat{\mathbf u}
\left(\widehat{\mathbf u}\cdot\mathbf v\right)
(1-\cos\theta).
}
\end{equation}
This is Rodrigues' rotation formula.

The quaternion formula and Rodrigues' formula therefore describe the same
rotation.  The quaternion form packages the rotation into multiplication, while
Rodrigues' formula displays the vector geometry explicitly.

\section{Parallel and perpendicular components}

Decompose the vector into components parallel and perpendicular to the axis:
\begin{equation}
\mathbf v_{\parallel}
=\left(\widehat{\mathbf u}\cdot\mathbf v\right)\widehat{\mathbf u},
\end{equation}
\begin{equation}
\mathbf v_{\perp}
=\mathbf v-\mathbf v_{\parallel}.
\end{equation}
Because
\[
\widehat{\mathbf u}\times\mathbf v_{\parallel}=0,
\]
Rodrigues' formula can be written as
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v_{\parallel}
+\mathbf v_{\perp}\cos\theta
+\left(\widehat{\mathbf u}\times\mathbf v_{\perp}\right)\sin\theta.
}
\end{equation}
This form makes the geometry immediate.  Rotation leaves
$\mathbf v_{\parallel}$ unchanged and performs an ordinary planar rotation on
$\mathbf v_{\perp}$ in the plane perpendicular to $\widehat{\mathbf u}$.

\section{A computational vector formula}

For software, write the unit quaternion as
\begin{equation}
q=(q_w,\mathbf q),
\end{equation}
where $\mathbf q$ is the three-component vector part.  Expanding the sandwich
product gives the equivalent formula
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v
+2q_w\left(\mathbf q\times\mathbf v\right)
+2\mathbf q\times\left(\mathbf q\times\mathbf v\right).
}
\end{equation}
This form avoids constructing the intermediate pure quaternion explicitly and
is often convenient in numerical code.

An equivalent two-step implementation is
\begin{equation}
\mathbf t=2\left(\mathbf q\times\mathbf v\right),
\end{equation}
\begin{equation}
\boxed{
\mathbf v'
=\mathbf v+q_w\mathbf t+\mathbf q\times\mathbf t.
}
\end{equation}
The formula assumes that $q$ is unit and that the Hamilton active-rotation
convention used in this entry is being followed.

\section{Basic checks}

Several simple cases are useful for checking both derivations and software.

\subsection*{Identity rotation}

For $\theta=0$,
\[
q=1,
\]
so
\begin{equation}
\mathbf v'=1\,\mathbf v\,1=\mathbf v.
\end{equation}

\subsection*{Vector along the axis}

If
\[
\mathbf v=\lambda\widehat{\mathbf u},
\]
then $\widehat{\mathbf u}\times\mathbf v=0$ and Rodrigues' formula gives
\begin{equation}
\boxed{\mathbf v'=\mathbf v.}
\end{equation}
The rotation axis is therefore a fixed direction.

\subsection*{Inverse rotation}

The inverse active rotation is obtained with $q^{-1}=q^*$:
\begin{equation}
\boxed{
\mathbf v=q^*\mathbf v' q.
}
\end{equation}
Thus exchanging $q$ and $q^*$ reverses the physical rotation angle.

\subsection*{Quaternion sign}

The two unit quaternions $q$ and $-q$ give the same rotation because
\begin{equation}
(-q)\mathbf v(-q)^*=q\mathbf v q^*.
\end{equation}

\section{Worked check: $+90^\circ$ about $+z$}

For a positive $90^\circ$ rotation about $+z$,
\begin{equation}
q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k.
\end{equation}
Let
\[
\mathbf v=\mathbf i.
\]
Then
\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}
Multiplying by
\[
q^*=\frac{\sqrt2}{2}-\frac{\sqrt2}{2}\mathbf k
\]
gives
\begin{equation}
\boxed{
q\mathbf i q^*=\mathbf j.
}
\end{equation}
Thus
\[
\hat{\mathbf x}\longrightarrow\hat{\mathbf y},
\]
which is the expected right-handed positive rotation about $+z$.

\section{Active and passive interpretations}

Equation (1) is an active rotation.  The coordinate frame is held fixed while
the physical vector is rotated.

If instead the physical vector is fixed and the coordinate frame is rotated by
the same positive orientation represented by $q$, the coordinates transform
with the inverse action:
\begin{equation}
\boxed{
\mathbf v_{\mathrm{new\ frame}}
=q^*\mathbf v_{\mathrm{old\ frame}}q.
}
\end{equation}
For example, a fixed vector along $+x$ has coordinates $[1,0,0]^T$ in the
original frame.  After the coordinate axes are rotated $+90^\circ$ about $+z$,
its new coordinates are
\[
[0,-1,0]^T.
\]
This is not a contradiction.  Active vector rotation and passive coordinate
change are inverse operations.

\section{Why unit length matters}

If $q$ is unit, conjugate and inverse are identical and equation (1) preserves
vector magnitude.  Using multiplicativity of the quaternion norm,
\begin{equation}
\begin{aligned}
\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}
If a nonunit quaternion is inserted into $q\mathbf vq^*$, the result is scaled
by $\lVert q\rVert^2$.  In numerical work, normalize the orientation quaternion
before applying the conjugate form, or use the true inverse if a general
nonzero quaternion is intentionally being used.

\section{Common pitfalls}

\begin{enumerate}
\item \textbf{Forgetting the zero scalar part of a vector.}
A three-dimensional vector enters quaternion multiplication as
$[0,v_x,v_y,v_z]^T$ in scalar-first layout.

\item \textbf{Using $q^*\mathbf vq$ when the intended operation is the active
rotation in equation (1).}
Under the convention used here, that expression performs the inverse rotation.

\item \textbf{Using a nonunit quaternion with the conjugate formula.}
For nonunit $q$, the conjugate is not the inverse.

\item \textbf{Confusing frame handedness with component storage.}
A right-handed frame describes the orientation of the physical basis.  Scalar-first
and scalar-last describe only where the scalar component appears in an array.

\item \textbf{Changing scalar-first to scalar-last without changing software
indices.}
The quaternion is the same mathematical object, but code must read the scalar
and vector parts from the correct positions.

\item \textbf{Changing a sign to match another source before checking its
rotation convention.}
The sign may arise from active versus passive interpretation, map direction, or
a different multiplication convention.
\end{enumerate}

\section{What comes next}

This entry establishes how one unit quaternion acts on one vector.  The next
PhysicsLibrary article develops composition of finite rotations and explains
why the order of quaternion multiplication matters.  That discussion will use
the same sandwich action to show how two successive rotations combine into one
unit quaternion.

A separate companion entry, \emph{Rotating Vectors with Quaternions: Examples,
Exercises, and Solutions}, provides a self-study problem set.  All exercises are
stated before the solutions.

\section{Sources and historical notes}

Hathaway's \emph{A Primer of Quaternions} gives the classical rotator
$q(\cdot)q^{-1}$ and states that a quaternion of angle $\phi$ rotates the
represented object through $2\phi$.  Joly likewise states that a conical rotation
about the axis of $q$ through double the quaternion angle changes an arbitrary
vector $\mathbf p$ into $q\mathbf p q^{-1}$.  Joly also gives rigid-body examples
using this transformation.  These public-domain sources provide direct
historical support for the sandwich action.

Macfarlane develops finite rotations and their composition using half-angle
versors, while Moore gives modern engineering treatment of right-handed
reference frames, orientations, and direction-cosine matrices.  The notation,
Rodrigues derivation, computational formulas, examples, and engineering
organization in this entry 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}

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

\bibitem{Moore2026}
J. K. Moore,
\emph{Learn Multibody Dynamics}, 2026 edition,
especially the chapter ``Orientation of Reference Frames.''
Creative Commons Attribution 4.0 International.
\PMlinkexternal{Learn Multibody Dynamics}{https://moorepants.github.io/learn-multibody-dynamics/}

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