Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random  

rotating vectors with quaternions

(Topic)

Rotating Vectors with Quaternions

Unit quaternions provide a compact way to transform vector coordinates between rotated orthonormal frames. The same algebra also describes active rotation of a physical vector, but the two interpretations use inverse quaternions for the same positive geometric rotation.

PhysicsLibrary takes the passive frame map as the canonical attitude interpretation. If frame B is obtained from frame A by a positive frame rotation through angle 𝜃 about the unit axis u, then

          𝜃        𝜃
BqA =  cos--− ^u sin--.
          2        2
(1)

A fixed physical vector v whose coordinates in frame A are Av has coordinates in frame B

B    B    A  B    ∗
 v =   qA  v(  qA) .
(2)

The vector is represented inside the quaternion product as a pure quaternion with zero scalar part.

Equation (2) is the central result of this article. The derivation below shows that it is exactly equivalent to the passive form of Rodrigues’ rotation formula,

                (       )         (      )
Bv =  Av cos𝜃 −  ^u × Av  sin 𝜃 + u^ ^u ⋅ Av (1 − cos 𝜃).
(3)

The minus sign on the cross product term is expected: the physical vector is fixed while the coordinate frame rotates positively.

1 Convention declaration

PhysicsLibrary uses Hamilton multiplication,

ij = k,    jk =  i,     ki = j,

with reversed products changing sign.

A quaternion is written scalar first,

                     ⌊qw⌋
                     |  |
q = qw + q    ←→     |qx| .
                     ⌈qy⌉
                      qz
(4)

For two quaternions

p = (p ,p ),    q = (q ,q ),
      w               w

Hamilton multiplication is

pq = (pwqw − p ⋅ q, pwq + qwp + p × q ).
(5)

The canonical frame quaternion Bq A maps coordinates from A into B. Frame chains therefore follow

CqA =  CqB BqA.
(6)

The active rotor for the corresponding positive physical vector rotation is the inverse,

          B   ∗       𝜃-       𝜃-
qactive = ( qA)  = cos 2 + ^usin 2.
(7)

Keeping these two quaternions distinct prevents most sign mistakes in vector rotation formulas.

2 Vectors as pure quaternions

A Cartesian vector

v = v ^x + v ^y + v ^z
     x     y      z

is embedded in quaternion algebra as the pure quaternion

v = 0 + vxi + vyj + vzk.
(8)

In scalar first component form,

       ⌊   ⌋
         0
       || vx||
[v ]PL = ⌈ vy⌉ .

         vz
(9)

The zero scalar part is important. The vector is not stored as an arbitrary four component quantity; it is embedded in the pure quaternion subspace.

For a pure quaternion v,

v∗ = − v.
(10)

Its quaternion norm equals the ordinary Euclidean vector magnitude,

       ∘ ------------
∥v∥ =    v2x + v2y + v2z.
(11)

3 Why the sandwich product preserves purity

Let

q = (qw, q)

be a unit quaternion and let

v = (0,v)

be pure. Consider

v′ = qvq∗.

Conjugating the complete product gives

  ′ ∗       ∗ ∗
(v ) =  (qvq  ).

Conjugation reverses factor order:

  ′ ∗     ∗ ∗
(v ) = qv  q .

Since v∗ = −v,

  ′ ∗        ∗      ′
(v ) =  − qvq =  − v.

Therefore

(v′)∗ = − v′,
(12)

which means v′ is also pure.

Thus a unit quaternion sandwich maps ordinary three dimensional vectors back into the pure quaternion subspace.

4 Why the sandwich product preserves vector magnitude

For a unit quaternion,

∥q∥ = ∥q ∗∥ =  1.

Quaternion norm multiplicativity gives

     ∗             ∗
∥qvq  ∥ = ∥q∥∥v∥ ∥q ∥
       =  ∥v∥.

Therefore

∥Bv ∥ = ∥Av∥.
(13)

A passive quaternion coordinate transformation changes only the components used to describe the vector. Its physical Euclidean length is unchanged.

5 Derivation of the passive vector transformation

Let

q = BqA =  c − s^u,
(14)

where

       𝜃-             𝜃-
c = cos2 ,    s = sin 2.

Then

q∗ = c + su^.
(15)

Let the input vector be the pure quaternion v.

First multiply q by v. Using the scalar vector Hamilton product,

qv = (s^u ⋅ v, cv −  s^u × v ).
(16)

Now multiply by q∗. The scalar part of the final product cancels, and the vector part becomes

vB  = (c2 − s2)v

       − 2cs(^u × v )
       + 2s2^u (^u ⋅ v).
(17)

Using

 2    2
c  − s =  cos𝜃,

2cs = sin𝜃,

and

2s2 = 1 − cos𝜃,

gives

vB = v cos 𝜃 − (^u × v)sin𝜃 + ^u (u^⋅ v)(1 − cos𝜃).
(18)

Restoring the frame labels,

Bv = Av  cos𝜃 − (^u × Av )sin 𝜃 + ^u(^u ⋅ Av )(1 − cos𝜃).
(19)

This is the passive Rodrigues formula.

6 Geometric interpretation of the passive Rodrigues formula

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

v =  v∥ + v⊥,
(20)

where

v ∥ = u^(^u ⋅ v)
(21)

and

v ⊥ = v − v∥.
(22)

The component parallel to the axis is unchanged. The perpendicular component is resolved along two perpendicular directions,

v ⊥

and

u^×  v.

Equation (19) can therefore be written

vB =  v∥ + v⊥ cos𝜃 − (^u × v) sin 𝜃.
(23)

The negative sine term expresses the coordinate motion opposite the positive frame rotation.

PIC

Figure 1:Passive quaternion vector transformation in the PhysicsLibrary convention. Frame B is obtained from frame A by a positive rotation through angle 𝜃 about u, so the canonical frame quaternion is Bq A = cos(𝜃∕2) −u sin(𝜃∕2). A fixed physical vector is represented by different coordinate columns in the two frames and transforms according to Bv = Bq A Av (Bq A)∗. The equivalent passive Rodrigues formula carries the negative cross product term because the basis rotates positively while the physical vector remains fixed.

Figure 1 provides a compact visual summary of the passive coordinate interpretation used throughout this entry.

7 Worked check: positive 90 ∘ frame rotation about +z

Let frame B be obtained from frame A by a positive 90∘ frame rotation about +z.

Then

^u = k,     𝜃 = 90 ∘,

and

         --     --
       √ 2    √ 2
BqA  = ----−  ---k.
        2      2
(24)

Take the fixed physical vector with frame A coordinates

A
  v = i.
(25)

The passive Rodrigues formula gives

k ⋅ i = 0

and

k × i = j.

Therefore

B
  v = − j.
(26)

Thus

⌊  ⌋       ⌊   ⌋
  1          0
⌈ 0⌉  − →  ⌈− 1⌉  .
  0          0
    A            B

Nothing physical has rotated. The coordinates changed because the frame axes rotated positively.

8 Direct quaternion multiplication for the same check

Let

     √ --
a =  --2.
      2

Then

BqA  = a(1 − k),     (BqA)∗ = a(1 + k).

First,

BqA i = a(1 − k)i

      = a(i − ki)
      = a(i − j).

Then

BqA  i(BqA)∗ = a2(i − j)(1 + k)

             = 1-(i − j + ik − jk)
               2
               1-
             = 2 (i − j − j − i)
             = − j.

The direct Hamilton multiplication agrees with the passive Rodrigues formula.

9 The corresponding active vector rotation

Now hold the coordinate frame fixed and physically rotate the vector through the same positive angle 𝜃 about the same axis.

The active rotor is the conjugate of the passive frame quaternion:

qactive = (BqA)∗ = cos 𝜃+  ^usin 𝜃.
                      2        2
(27)

The active vector rotation is

v′ = q    v q∗   .
     active   active
(28)

Repeating the derivation with the positive vector part gives the familiar active Rodrigues formula,

 ′
v  = v cos𝜃 + (^u × v )sin 𝜃 + ^u(^u ⋅ v )(1 − cos 𝜃).
(29)

Thus the passive and active formulas differ only in the sign of the sine term when the same positive geometric angle and axis are used.

For a positive 90∘ active rotation about +z,

i − → j,

while for the corresponding positive 90∘ frame rotation,

Av  = i  − →    Bv =  − j.

These statements are not contradictory. One rotates the physical vector; the other rotates the coordinate frame.

10 Inverse transformation

Starting from the passive map

B    B    A  B    ∗
 v =   qA  v(  qA) ,
(30)

multiply on the left by (Bq A)∗ and on the right by Bq A.

Since the frame quaternion is unit,

(BqA )∗BqA = 1.

Therefore

Av = (Bq  )∗Bv Bq  .
         A       A
(31)

Using

A      B    ∗
 qB = (  qA) ,

this becomes

A    A   B   A    ∗
 v =   qB  v(  qB) .
(32)

The same sandwich structure is retained; only the frame quaternion is inverted.

11 Quaternion sign ambiguity

A unit quaternion and its negative represent the same coordinate transformation.

Because

     ∗      ∗
(− q) =  − q ,

we have

          ∗             ∗
(− q )v (− q) = (− q)v(− q )
            = qvq∗.

Therefore

q  and    − q
(33)

produce exactly the same vector transformation.

This double representation matters in numerical attitude estimation and interpolation because a sign change in the quaternion array does not imply a physical attitude jump.

12 Vector only implementation

The sandwich product can be evaluated without explicitly constructing two full quaternion products.

Let

q = (qw, q)

be any unit Hamilton quaternion used in

 ′      ∗
v =  qvq .

Expanding the sandwich product gives

v′ = v + 2qw(q × v ) + 2q × (q ×  v).
(34)

Define

t = 2(q × v ).
(35)

Then

v ′ = v + qwt + q × t.
(36)

This form is useful in software because it uses only vector additions, scalar multiplications, and cross products.

For the canonical passive frame quaternion,

           𝜃
q = − ^u sin --,
           2

so the same implementation automatically produces the passive sign. No special passive version of Hamilton multiplication is required.

13 Matrix form

Define the cross product matrix of a vector a by

       ⌊                ⌋
          0    − az  ay
[a]× = ⌈  az    0   − ax⌉ ,
         − ay  ax     0
(37)

so that

[a]×v =  a × v.

For a unit quaternion

q = (qw,q ),

the sandwich product corresponds to the matrix

          2                T
C (q) = (qw − q ⋅ q)I + 2qq  + 2qw[q]×.
(38)

Thus

v′ = C (q)v.
(39)

For the passive frame quaternion

        𝜃-  ^    𝜃-
q = cos 2 − u sin 2,

equation (37) reduces to

BCA  =  I cos 𝜃 + (1 − cos 𝜃)^u^uT − [^u ]× sin 𝜃.
(40)

Therefore

Bv =  BCA Av
(41)

is exactly equivalent to the quaternion sandwich in equation (2).

The inverse matrix relation is

AC   = (BC  )T = C ((Bq )∗).
  B        A           A
(42)

14 A vector parallel to the rotation axis

If

v = λu^,

then

^u × v = 0

and

^u ⋅ v = λ.

The passive Rodrigues formula becomes

vB  = λ^u cos𝜃 + λ ^u(1 − cos𝜃)
    = λ^u.

Therefore

vB = v.
(43)

The rotation axis is an eigenvector of the coordinate transformation with eigenvalue one.

15 A vector perpendicular to the rotation axis

If

^u ⋅ v = 0,

then the passive Rodrigues formula reduces to

v  =  vcos 𝜃 − (^u × v)sin 𝜃.
 B
(44)

The transformed coordinates remain in the plane perpendicular to the rotation axis.

For the corresponding active rotation,

v ′ = v cos𝜃 + (^u × v )sin𝜃.
(45)

The opposite signs again reflect inverse geometric operations.

16 Why unit norm is required

Suppose one attempts to use

r = αq

with q unit and real α≠1.

Then

r∗ = αq ∗

and

rvr∗ = (αq)v(αq ∗)
        2    ∗
     = α qvq .

Therefore

∥rvr∗∥ = α2∥v ∥.
(46)

The conjugate sandwich represents a pure orthogonal transformation only for a unit quaternion.

For a general nonzero quaternion, a similarity transformation can instead be written

 ′      −1
v  = rvr  .
(47)

Since

         ∗
r−1 = -r---,
      ∥r ∥2

the scale factor then cancels. Orientation calculations normally avoid this extra division by maintaining the attitude quaternion at unit norm.

17 Implementation checks

A quaternion vector transformation routine should pass several simple tests.

  1. identity.

    For q = 1,

       ∗
qvq  = v.
  2. Positive passive    ∘
90 about +z  .

    Using

           √ --   √ --
B        2      2
  qA = ----−  ---k,
        2      2

    the fixed vector with Av = i must give

    Bv =  − j.
  3. Positive active 90∘ about +z  .

    Using the conjugate rotor,

            √ --  √ --
        --2-  --2-
qactive =  2  +  2  k,

    the physical vector must transform as

    i − → j.
  4. Axis invariance.

    A vector parallel to the rotation axis must remain unchanged.

  5. Norm preservation.

    For unit q,

    ∥qvq∗∥ = ∥v ∥.
  6. Quaternion sign.

    Replacing q by −q must not change the output vector.

  7. Inverse.

    Applying q and then q∗ in the corresponding inverse frame map must recover the original coordinates.

These checks detect sign, multiplication order, normalization, and active versus passive mistakes quickly.

18 Common pitfalls

  1. Using the active quaternion sign for the canonical passive frame map.

    For a positive frame rotation,

    Bq  =  cos 𝜃-− ^u sin 𝜃-.
  A       2        2

    The conjugate has the positive vector sign and is the corresponding active rotor.

  2. Using the wrong sandwich order.

    PhysicsLibrary’s canonical passive map is

    Bv = Bq   Av(Bq  )∗.
        A       A

    The inverse map uses the conjugate quaternion as the new frame quaternion.

  3. Forgetting the pure quaternion embedding.

    The vector entering the sandwich product has zero scalar part.

  4. Assuming q  and − q  represent different orientations.

    They produce the same sandwich transformation.

  5. Using a nonunit quaternion with the conjugate sandwich.

    A nonunit scale changes vector magnitude unless the true inverse is used.

  6. Changing Hamilton multiplication to obtain a passive transformation.

    No multiplication change is needed. PhysicsLibrary retains Hamilton multiplication and encodes the passive frame direction in the quaternion definition and frame labels.

  7. Confusing coordinate motion with physical vector motion.

    For the same positive axis and angle, a passive frame rotation produces the inverse coordinate motion of the corresponding active vector rotation.

  8. Copying Rodrigues’ formula without checking the interpretation.

    The active formula has a positive cross product sine term. The PhysicsLibrary passive coordinate formula has a negative cross product sine term.

19 Relationship to adjacent PhysicsLibrary entries

The preceding article, Axis Angle Representation and Unit Quaternion, constructs the passive frame quaternion

Bq  =  cos 𝜃-− ^u sin 𝜃-.
  A       2        2

The present article shows how that quaternion acts on vector coordinates and derives its Rodrigues and matrix forms.

A separate companion entry, Rotating Vectors with Quaternions: Examples, Exercises, and Solutions, provides the self study problem bank using the same passive convention.

The next main article, composition of rotations and quaternion order, uses the sandwich action developed here to derive composition order, frame chains, intrinsic sequences, and the noncommutativity of finite rotations.

20 Sources and convention notes

The quaternion sandwich transformation is classical. Hamilton, Joly, and Hathaway develop quaternion rotation through conjugation by a unit quaternion or versor. Modern engineering sources often state the same algebra using active vector rotations. PhysicsLibrary retains Hamilton multiplication but takes the passive frame coordinate map as the canonical attitude object.

Sommer and coauthors provide a useful modern discussion of Hamilton versus flipped quaternion multiplication and the interaction between multiplication convention and passive attitude mappings. The derivations in this entry are written specifically for the PhysicsLibrary passive convention.

References

[1]   W. R. Hamilton, Elements of Quaternions, 2nd ed., edited by C. J. Joly, Longmans, Green, and Co., 1899. Public domain historical source. Internet Archive scan

[2]   C. J. Joly, A Manual of Quaternions, Macmillan and Co., London, 1905. Public domain historical source. Internet Archive scan

[3]   A. S. Hathaway, A Primer of Quaternions, 1896. Public domain historical source. Project Gutenberg edition

[4]   H. Sommer, I. Gilitschenski, M. Bloesch, S. Weiss, R. Siegwart, and J. Nieto, “Why and How to Avoid the Flipped Quaternion Multiplication,” Aerospace, vol. 5, no. 3, article 72, 2018. Published under CC BY 4.0. Publisher article

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:
See Also: quaternion series overview and article guide, Quaternions for Physics and Engineering: Orientation, Notation, and Conventions, quaternion definition and basic algebra, example of quaternion definition and basic algebra, quaternion product, example of quaternion product, quaternion conjugate, example of quaternion conjugate, quaternion norm, example of quaternion norm, quaternion inverse, example of quaternion inverse

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: composition, composition of rotations and quaternion order, Axis Angle Representation and Unit Quaternion, detect, identity, norm, operations, relation, matrix, vector additions, representation, conjugation, magnitude, quaternion norm, cross product, formula, scalar, quaternion product, vector, quaternions, unit
There are 4 references to this object.

This is version 5 of rotating vectors with quaternions, born on 2026-08-23, modified 2026-08-27.
Object id is 1097, canonical name is RotatingVectorsWithQuaternions.
Accessed 326 times total.

Classification:
Physics Classification: 02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)

Pending Errata and Addenda

None.

Discussion

No messages.

Interact