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

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

$\displaystyle \boxed{ \mathbf v' = q\,\mathbf v\,q^*. }$ (1)
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.

Convention declaration

This entry uses Hamilton multiplication in a right-handed Cartesian frame:

$\displaystyle \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,
$\displaystyle q=q_w+q_x\mathbf i+q_y\mathbf j+q_z\mathbf k \quad\longleftrightarrow\quad \begin{bmatrix} q_w&q_x&q_y&q_z \end{bmatrix}^{T}.$ (2)
Scalar-last arrays such as

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

For a rotation through angle $\theta$ about the unit axis $\widehat{\mathbf u}$, the unit quaternion is

$\displaystyle \boxed{ q =\cos\frac{\theta}{2} +\widehat{\mathbf u}\sin\frac{\theta}{2}. }$ (3)
Because $\lVert q\rVert=1$,
$\displaystyle q^{-1}=q^*.$ (4)

Representing a vector as a pure quaternion

Let the ordinary vector be

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

The quaternion sandwich action

Let

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

Figure [*] 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 .

Figure: Quaternion rotation of a vector about the unit axis . The parallel component $\mathbf v_{\parallel}$ is unchanged. The perpendicular component rotates through , carrying to .
Image Q07_quaternion_vector_rotation

Derivation using scalar and vector parts

The scalar–vector form of the Hamilton product is

$\displaystyle (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).$ (10)
Write

$\displaystyle q=(c,s\widehat{\mathbf u}), \qquad \mathbf v=(0,\mathbf v). $
The first multiplication gives
$\displaystyle q\mathbf v = \left( -s\widehat{\mathbf u}\cdot\mathbf v, \;c\mathbf v+s\widehat{\mathbf u}\times\mathbf v \right).$ (11)
Multiplying this result by

$\displaystyle 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' ={}&(c^2-s^2)\mathbf v +2cs\left(\wi... ... u} \left(\widehat{\mathbf u}\cdot\mathbf v\right). \end{aligned}\end{equation*}
Using the half-angle identities
$\displaystyle c^2-s^2=\cos\theta, \qquad 2cs=\sin\theta, \qquad 2s^2=1-\cos\theta,$ (13)
we obtain
$\displaystyle \boxed{ \mathbf v' =\mathbf v\cos\theta +\left(\widehat{\mathbf u... ...hat{\mathbf u} \left(\widehat{\mathbf u}\cdot\mathbf v\right) (1-\cos\theta). }$ (14)
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.

Parallel and perpendicular components

Decompose the vector into components parallel and perpendicular to the axis:

$\displaystyle \mathbf v_{\parallel} =\left(\widehat{\mathbf u}\cdot\mathbf v\right)\widehat{\mathbf u},$ (15)
$\displaystyle \mathbf v_{\perp} =\mathbf v-\mathbf v_{\parallel}.$ (16)
Because

$\displaystyle \widehat{\mathbf u}\times\mathbf v_{\parallel}=0, $
Rodrigues' formula can be written as
$\displaystyle \boxed{ \mathbf v' =\mathbf v_{\parallel} +\mathbf v_{\perp}\cos\theta +\left(\widehat{\mathbf u}\times\mathbf v_{\perp}\right)\sin\theta. }$ (17)
This form makes the geometry immediate. Rotation leaves unchanged and performs an ordinary planar rotation on $\mathbf v_{\perp}$ in the plane perpendicular to .

A computational vector formula

For software, write the unit quaternion as

$\displaystyle q=(q_w,\mathbf q),$ (18)
where $\mathbf q$ is the three-component vector part. Expanding the sandwich product gives the equivalent formula
$\displaystyle \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). }$ (19)
This form avoids constructing the intermediate pure quaternion explicitly and is often convenient in numerical code.

An equivalent two-step implementation is

$\displaystyle \mathbf t=2\left(\mathbf q\times\mathbf v\right),$ (20)
$\displaystyle \boxed{ \mathbf v' =\mathbf v+q_w\mathbf t+\mathbf q\times\mathbf t. }$ (21)
The formula assumes that is unit and that the Hamilton active-rotation convention used in this entry is being followed.

Basic checks

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

Identity rotation

For $\theta=0$,

$\displaystyle q=1, $
so
$\displaystyle \mathbf v'=1\,\mathbf v\,1=\mathbf v.$ (22)

Vector along the axis

If

$\displaystyle \mathbf v=\lambda\widehat{\mathbf u}, $
then $\widehat{\mathbf u}\times\mathbf v=0$ and Rodrigues' formula gives
$\displaystyle \boxed{\mathbf v'=\mathbf v.}$ (23)
The rotation axis is therefore a fixed direction.

Inverse rotation

The inverse active rotation is obtained with $q^{-1}=q^*$:

$\displaystyle \boxed{ \mathbf v=q^*\mathbf v' q. }$ (24)
Thus exchanging and reverses the physical rotation angle.

Quaternion sign

The two unit quaternions and $-q$ give the same rotation because

$\displaystyle (-q)\mathbf v(-q)^*=q\mathbf v q^*.$ (25)

Worked check: $+90^\circ$ about $+z$

For a positive $90^\circ$ rotation about ,

$\displaystyle q=\frac{\sqrt2}{2}+\frac{\sqrt2}{2}\mathbf k.$ (26)
Let

$\displaystyle \mathbf v=\mathbf i. $
Then
\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*}
Multiplying by

$\displaystyle q^*=\frac{\sqrt2}{2}-\frac{\sqrt2}{2}\mathbf k $
gives
$\displaystyle \boxed{ q\mathbf i q^*=\mathbf j. }$ (28)
Thus

$\displaystyle \hat{\mathbf x}\longrightarrow\hat{\mathbf y}, $
which is the expected right-handed positive rotation about .

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 , the coordinates transform with the inverse action:

$\displaystyle \boxed{ \mathbf v_{\mathrm{new\ frame}} =q^*\mathbf v_{\mathrm{old\ frame}}q. }$ (29)
For example, a fixed vector along $+x$ has coordinates $[1,0,0]^T$ in the original frame. After the coordinate axes are rotated about , its new coordinates are

$\displaystyle [0,-1,0]^T. $
This is not a contradiction. Active vector rotation and passive coordinate change are inverse operations.

Why unit length matters

If 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 &=\lVert q\rVert\,\l... ...Vert\,\lVert q^*\rVert \ &=\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.

Common pitfalls

  1. 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.
  2. 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.
  3. Using a nonunit quaternion with the conjugate formula. For nonunit , the conjugate is not the inverse.
  4. 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.
  5. 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.
  6. 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.

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, Rotating Vectors with Quaternions: Examples, Exercises, and Solutions, provides a self-study problem set. All exercises are stated before the solutions.

Sources and historical notes

Hathaway's 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 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.

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 available. Project Gutenberg edition
4
J. K. Moore, Learn Multibody Dynamics, 2026 edition, especially the chapter “Orientation of Reference Frames.” Creative Commons Attribution 4.0 International. Learn Multibody Dynamics

License

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



"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, rigid-body attitude

Attachments:
example of rotating vectors with quaternions (Example) by bloftin

Cross-references: matrices, reference frames, composition, positions, work, quaternion norm, magnitude, operations, identities, quaternion multiplication, scalar, formula, vector, quaternion
There is 1 reference to this object.

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