Physics Library
 An open source physics library
Encyclopedia | Forums | Docs | Random |  
Login
create new user
Username:
Password:
forget your password?
Main Menu
Sections

Meta

Talkback

Downloads

Information
[parent] example of relative attitude and error quaternions (Example)

Relative Attitude and Error Quaternions: Examples, Exercises, and Solutions

This entry is the self study companion to the PhysicsLibrary article relative attitude and error quaternions. All exercises are stated first. Complete worked solutions follow afterward.

Let the current or actual passive attitude be

q = BqI

and the desired passive attitude be

q  = Dq .
 d      I

The two multiplicative error definitions used throughout are

δqL = qdq∗,
(1)

δqR =  q∗qd.
(2)

They reconstruct the desired attitude as

qd = δqLq
(3)

or

qd = qδqR.
(4)

For a passive positive small frame error vector δ𝜃,

     [     ]
        1
δq ≈  − 1δ𝜃  ,
        2
(5)

so

δ 𝜃 ≈ − 2δqv.
(6)

1 Exercises

  1. identity error.

    Suppose

    qd = q.

    Compute both δqL and δqR.

    What physical attitude error do they represent?

  2. Opposite stored quaternion sign.

    Suppose

    qd = − q.

    Compute the raw left and right error quaternions.

    Explain why the physical attitude error is still zero and state the principal error quaternion that should normally be used locally.

  3. Same axis desired versus actual yaw.

    The current attitude is a positive passive frame yaw of 10:

    q = cos5∘ − k sin 5∘.

    The desired attitude is a positive passive frame yaw of 25:

    qd = cos 12.5∘ − k sin12.5∘.

    Compute δqL and δqR and recover the physical frame error axis and angle.

  4. Noncommuting left and right errors.

    Let

        1 − i
q = -√---
       2

    and

         1 − j
qd = -√---.
        2

    These are positive passive 90 frame rotations about +x and +y, respectively.

    Compute δqL and δqR.

    Recover the principal physical frame error angle and axis for each.

  5. direction cosine matrix error check.

    For the attitudes in Exercise 4, use

           ⌊          ⌋
         1   0   0
C (q ) = ⌈ 0  0   1⌉

         0  − 1  0

    and

            ⌊          ⌋
          0  0  − 1
C (q) = ⌈ 0  1   0 ⌉ .
    d
          1  0   0

    Compute

              T
EL =  CdC

    and

    E  =  CT C .
 R        d

    Verify that they equal C(δqL) and C(δqR).

  6. Principal quaternion sign.

    An error computation returns

         ⌊             ⌋
      − 0.99904822
     ||      0      ||
δq = ⌈      0      ⌉ .

       0.04361939
    (7)

    Choose the principal representative with nonnegative scalar part.

    Then determine the physical passive frame error angle and axis.

  7. Exact passive axis angle extraction.

    Consider

         ⌊  √2 ⌋
        2√--
     ||− --6||
δq = |  √66-| .
     ⌈− √6-⌉
      − -66
    (8)

    Verify that it is unit norm and recover the positive physical frame error axis and angle.

  8. Small error vector from a quaternion.

    A local passive error quaternion is approximated by

         ⌊   1   ⌋
     |       |
δq ≈ |− 0.005| .
     ⌈ 0.010 ⌉
      − 0.015
    (9)

    Recover the corresponding first order physical frame error vector in radians and degrees.

  9. Transport a right small error to the left.

    The current attitude is

    q =  1 −√-k,
        2

    so

            ⌊ 0   1  0⌋
        ⌈         ⌉
C (q) =  − 1  0  0  .
          0   0  1

    A right small error vector is

           ⌊0.020⌋
       ⌈     ⌉
δ𝜃R =   0.010  rad.
          0

    Compute δ𝜃L and the first order left and right error quaternions.

  10. Left error estimation injection.

    A nominal estimate is a positive passive yaw of 20:

     −         ∘          ∘
^q  = cos 10 −  ksin 10 .

    A filter using a left multiplicative error estimates a positive 2 frame yaw correction.

    Construct δqL and compute

    ^q+ = δ^qLq^− .

    Interpret the corrected attitude.

  11. Right error injection with noncommuting axes.

    The nominal attitude is

     −   1 − k
^q  = --√---,
        2

    a positive passive 90 yaw.

    A right error model estimates a positive 10 frame rotation about its positive x axis:

    δ^qR = cos 5∘ − i sin 5∘.

    Compute

    ^q+ = ^q− δ^qR.

    Give scalar first numerical components.

  12. Physical control correction from a passive error quaternion.

    A controller forms the principal left error

          ⌊        ⌋
           1
δq  ≈ ||  0.005  || .
  L   ⌈ − 0.010 ⌉
         0.020
    (10)

    Find the first order physical frame correction vector δ𝜃L.

    Explain why using +2δqL,v would have the wrong sign under the PhysicsLibrary convention.

  13. relative attitude between two bodies.

    Two body frames have passive inertial attitudes

    B1qI = cos 15∘ − k sin 15∘

    and

    B            ∘          ∘
 2qI = cos 35 − k sin35 .

    Compute

    B2
  qB1.

    State the positive relative frame rotation.

  14. Why Euler Angle subtraction is not the exact error.

    Use the Exercise 4 attitudes to explain why subtracting two sets of Euler coordinates is not generally the same as computing the multiplicative quaternion error.

    Compare the exact principal error angle from Exercise 4 with the magnitude one might naively infer by treating two 90 axis rotations as ordinary orthogonal vector components.

  15. Near 180 ∘ principal sign behavior.

    Let

             ⌊ ⌋
          1
^u =  √1--⌈1⌉
       3  1

    and consider a positive passive frame error of 179.

    Write a principal error quaternion.

    What happens to the chosen quaternion sign if the error passes through 180 while a rule enforces δqw 0?

    Does the physical attitude become discontinuous?

  16. Error state consistency in a filter.

    A filter covariance is defined using a right multiplicative small error δ𝜃R, but a software update routine is written as

     +       −
^q  =  δ^q ^q .

    Explain why this is inconsistent.

    Give two correct alternatives: one that retains the right error definition, and one that transports the correction to a left error before injection.

2 Solutions

Solution 1: identity error

If

qd = q,

then

δqL = qq∗ = 1

and

δqR = q∗q = 1.

Therefore

δqL =  δqR = 1.
(11)

The physical attitude error is zero.

Solution 2: opposite stored quaternion sign

If

qd = − q,

then

δqL =  (− q)q∗ = − 1

and

δq  = q∗(− q) = − 1.
  R

Thus the raw errors are

δqL = δqR = − 1.
(12)

The quaternions +1 and 1 represent the same identity orientation. Therefore the physical attitude error is zero.

For a local principal representation, flip the sign:

δqprincipal = +1.
(13)

Solution 3: same axis desired versus actual yaw

The conjugate of the current attitude is

 ∗        ∘        ∘
q  = cos 5 + k sin5 .

Therefore

δqL = qdq∗
    = (cos12.5∘ − k sin 12.5∘)(cos5∘ + k sin 5∘)
            ∘           ∘
    = cos7.5  − k sin 7.5 .

Because both quaternions use the same axis, they commute, so

δqR = δqL = cos 7.5 ∘ − k sin7.5∘.
(14)

The quaternion half angle is 7.5, so the physical frame error is

δ𝜃 =  15∘,    ^ue = + ^z.
(15)

The negative k vector part is exactly the passive sign expected for a positive frame rotation about +z.

Solution 4: noncommuting left and right errors

The current conjugate is

     1 + i
q∗ = -√---.
        2

The left error is

          ∗
δqL =  qdq
       1-
    =  2(1 − j)(1 + i)
       1
    =  -(1 + i − j + k).
       2

Hence

δq  =  1(1 + i − j + k).
  L    2
(16)

The right error is

δqR =  q∗qd

    =  1(1 + i)(1 − j)
       2
       1-
    =  2(1 + i − j − k).

Hence

δq  =  1(1 + i − j − k).
  R    2
(17)

For both errors,

                      √ --
      1                 3
δqw = -,     ∥δqv∥ =  ---.
      2                2

Therefore

δ 𝜃
---=  60∘
 2

and

δ𝜃 = 120∘.
(18)

For the left error,

          ⌊    ⌋
            1
δq    = 1-⌈ − 1 ⌉.
   L,v   2
            1

Passive axis extraction gives

                      ⌊    ⌋
         δq        1    − 1
^uL =  − ---L,v--= √---⌈  1 ⌉.
        ∥δqL,v∥     3   − 1
(19)

For the right error,

          ⌊  1 ⌋
        1-⌈    ⌉
δqR,v = 2   − 1 ,
            − 1

so

          ⌊   ⌋
       1   − 1
^uR  = √---⌈ 1 ⌉ .
        3   1
(20)

The angle is the same, but the coordinates of the error axis differ.

Solution 5: direction cosine matrix error check

The current DCM is

     ⌊         ⌋
      1   0   0
C =  ⌈0   0   1⌉ ,
      0  − 1  0

and the desired DCM is

      ⌊0  0  − 1⌋
      ⌈         ⌉
Cd  =  0  1   0   .
       1  0   0

The left error matrix is

          T
EL  = CdC
      ⌊ 0  − 1  0 ⌋
      ⌈           ⌉
    =   0   0   − 1 .
        1   0   0

Thus

      ⌊           ⌋
        0  − 1  0
EL  = ⌈ 0   0   − 1⌉ .
        1   0   0
(21)

Converting

      1
δqL = 2-(1 + i − j + k )

with the Q09 quaternion to DCM formula gives exactly this matrix.

Similarly,

ER  = CT Cd
      ⌊           ⌋
         0   0  − 1
    = ⌈ − 1  0  0 ⌉ .
         0   1  0

Therefore

      ⌊           ⌋
         0   0  − 1
ER  = ⌈ − 1  0  0 ⌉ ,
         0   1  0
(22)

which agrees with

  ( 1              )
C   -(1 + i − j − k) .
    2

Solution 6: principal quaternion sign

The raw error has

δq  < 0.
  w

Multiply all four components by 1:

      ⌊  0.99904822 ⌋
      |             |
δqp = |       0     | .
      ⌈       0     ⌉
        − 0.04361939
(23)

The scalar is approximately

cos2.5∘

and the vector magnitude is approximately

sin 2.5∘.

Therefore

δ𝜃 = 5∘.

The vector part points in the k quaternion direction. Under the passive convention the physical positive frame axis is the opposite vector direction:

^u  =  +^z.
  e
(24)

Thus the error is a positive 5 frame rotation about +z.

Solution 7: exact passive axis angle extraction

The squared norm is

               (   )
∥ δq∥2 = 1-+ 3   6--
         2       36
         1   1
      =  2-+ 2-

      =  1.

Thus the quaternion is unit.

Its scalar component is

      √ --
        2         ∘
δqw = ----= cos 45 .
       2

Therefore

        ∘
δ𝜃 = 90 .
(25)

The vector part is

            ⌊  ⌋
        √6--  1
δqv = − ----⌈ 1⌉ .
         6    1

Its direction is opposite the physical passive frame axis, so

          ⌊1⌋
      -1--⌈ ⌉
u^e =  √3-- 1  .
           1
(26)

Solution 8: small error vector from a quaternion

For a passive small error,

δ 𝜃 ≈ − 2δqv.

Thus

         ⌊       ⌋
          − 0.005
δ𝜃 ≈ − 2 ⌈ 0.010 ⌉
          − 0.015
     ⌊        ⌋
        0.010
   = ⌈ − 0.020 ⌉ rad.
        0.030

Therefore

     ⌊        ⌋
        0.010
δ𝜃 ≈ ⌈ − 0.020 ⌉ rad.
        0.030
(27)

Using

                ∘
1 rad ≈ 57.2958 ,

the components are approximately

     ⌊       ∘ ⌋
        0.573 ∘
δ𝜃 ≈ ⌈ − 1.146  ⌉ .
        1.719∘
(28)

Solution 9: transport a right small error to the left

The relation is

δ𝜃  = C (q)δ𝜃  .
  L          R

Therefore

       ⌊ 0   1  0⌋ ⌊ 0.020 ⌋
       ⌈         ⌉ ⌈      ⌉
δ𝜃L =   − 1  0  0    0.010
         0   0  1      0
       ⌊ 0.010 ⌋
       ⌈       ⌉
    =   − 0.020  rad.
           0

Thus

       ⌊       ⌋
         0.010
δ𝜃L =  ⌈− 0.020⌉ rad.
           0
(29)

The first order right error quaternion is

      ⌊    1   ⌋
      |        |
δqR ≈ | − 0.010 | .
      ⌈ − 0.005 ⌉
           0

The first order left error quaternion is

      ⌊        ⌋
           1
      || − 0.005 ||
δqL ≈ ⌈  0.010  ⌉ .

           0
(30)

The two vector parts differ because the same geometric error is resolved on different sides of the current attitude map.

Solution 10: left error estimation injection

A positive 2 passive frame yaw correction has quaternion

δ^q  = cos1∘ − k sin 1∘.
  L
(31)

The left injection is

^q+ = δ^q q^− .
       L

Both rotations are about +z, so they commute and their frame angles add:

^q+ = (cos1 ∘ − k sin1∘)(cos 10∘ − ksin10 ∘)
           ∘          ∘
   = cos 11 −  ksin11  .

Thus

^q+ = cos 11∘ − ksin 11∘.
(32)

The corrected attitude is a positive passive frame yaw of

  ∘
22 .
(33)

Solution 11: right error injection with noncommuting axes

Let

    √ --
a = --2,     c = cos5∘,     s = sin 5∘.
     2

Then

^q+ = a(1 − k )(c − is).

Expanding with Hamilton multiplication,

 +
^q  = ac − asi + asj − ack.

Therefore

     ⌊     ⌋
        ac
 +   || − as||
^q  = ⌈  as ⌉ .

       − ac
(34)

Numerically,

a ≈  0.707106781,

c ≈ 0.996194698,      s ≈ 0.087155743.

Hence

      ⌊              ⌋
        0.704416026
 +    |− 0.061628417 |
^q  ≈  |⌈ 0.061628417  |⌉ .

       − 0.704416026
(35)

Because the correction axis is not the same as the nominal yaw axis, the product cannot be reduced by simply adding scalar angles.

Solution 12: physical control correction from a passive error quaternion

The vector part is

        ⌊        ⌋
           0.005
δq    = ⌈ − 0.010 ⌉.
   L,v
           0.020

For the PhysicsLibrary passive convention,

δ𝜃L ≈  − 2δqL,v.

Therefore

       ⌊       ⌋
        − 0.010
δ𝜃  ≈  ⌈ 0.020 ⌉ rad.
   L
        − 0.040
(36)

Using

+2 δqL,v

would produce the opposite physical frame correction because the passive quaternion vector part has the negative half angle sign.

Solution 13: relative attitude between two bodies

The direct relative attitude is

B2q   = B2q (B1q )∗.
   B1      I    I

The conjugate of the first attitude is

 B1   ∗        ∘          ∘
(  qI) = cos 15  + k sin 15 .

Therefore

B2qB1 = (cos 35∘ − ksin 35∘)(cos15∘ + k sin 15∘)
              ∘          ∘
      = cos 20  − k sin 20 .

Hence

B2qB1 = cos20∘ − k sin 20∘.
(37)

Because quaternion arguments use half angles, this represents a positive relative frame rotation of

40∘
(38)

about +z.

Solution 14: why Euler angle subtraction is not the exact error

Exercise 4 compares a positive 90 x frame rotation with a positive 90 y frame rotation.

The exact multiplicative quaternion error has scalar part

1
-.
2

Therefore the exact principal error angle is

        1-      ∘
2arccos 2 = 120  .

If one incorrectly treated the two 90 angle changes as orthogonal components of an ordinary Euclidean vector, one might form

∘  ---∘-2-----∘-2-       ∘
   (90 ) + (90 )  ≈ 127.3 .

That number is not the actual finite relative rotation.

The discrepancy occurs because finite rotations compose on a noncommutative group. Euler angle coordinates are sequence dependent nonlinear coordinates, not Cartesian components of a global attitude vector.

Solution 15: near 180∘ principal sign behavior

For a positive passive frame error of 179 about u,

δq = cos 89.5∘ − u^sin89.5∘.

Thus a principal quaternion is

            ∘   i + j + k       ∘
δq = cos89.5  − ---√-----sin89.5 .
                     3
(39)

Its scalar component is small but positive.

If the physical error passes beyond 180, the raw continuation of the same quaternion branch gives a negative scalar component. A policy that requires

δqw ≥ 0

will then multiply the quaternion by 1.

Consequently the stored quaternion components can switch sign even though the physical attitude changes continuously.

The physical orientation does not become discontinuous. The discontinuity belongs to the chosen principal quaternion representative.

Solution 16: error state consistency in a filter

A right multiplicative error is defined by

q = ^qδq  .
 t      R

Therefore a correction estimated in the right error coordinates must be injected on the right:

^q+ = ^q− δ^q .
          R
(40)

Using

 +        −
^q  = δq^R ^q

would reinterpret the same quaternion components as a left side correction, which is generally a different physical coordinate resolution.

One correct alternative is therefore to retain the right error definition and right inject it.

A second correct alternative is to transport the correction to the left side:

δ^q  = ^q− δq^ (^q− )∗,
  L       R
(41)

and then inject

 +        −
^q  = δ^qLq^ .
(42)

For a small error vector, the equivalent coordinate transport is

          −
δ^𝜃L =  C (^q  )δ^𝜃R.
(43)

The covariance definition, Jacobians, correction coordinates, and injection side must all use one consistent convention.

3 Compact passive error checks



Quantity PhysicsLibrary passive result


Left error δqL = qdq


Right error δqR = qq d


Left reconstruction qd = δqLq


Right reconstruction qd = qδqR


Small frame error δq [1,δ𝜃2]T


Recover small frame error δ𝜃 ≈−2δqv


Left/right relation δqL = qδqRq


Small vector transport δ𝜃L = C(q)δ𝜃R


4 Sources and exercise provenance

The exercises and solutions in this companion are newly written or rewritten for PhysicsLibrary under the passive frame convention.

Sommer and coauthors provide a modern convention analysis that helps separate Hamilton quaternion algebra from active and passive frame semantics. Markley and Crassidis provide a broad spacecraft attitude treatment including multiplicative attitude errors. Solà provides a detailed engineering discussion of quaternion perturbations and error state filtering; formulas must be translated carefully when its quaternion map differs from the PhysicsLibrary convention.

References

[1]   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

[2]   F. L. Markley and J. L. Crassidis, Fundamentals of Spacecraft Attitude Determination and Control, Springer, 2014. Engineering reference. Publisher book page

[3]   J. Solà, “Quaternion Kinematics for the Error State Kalman Filter,” technical report, 2017. arXiv preprint

[4]   M. D. Shuster, “The Nature of the Quaternion,” The Journal of the Astronautical Sciences, vol. 56, no. 3, pp. 359–373, 2008. Reference source. DOI record

License

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


"example of relative attitude and error quaternions" is owned by bloftin.
(view preamble)
View style:
See Also: quaternion series overview and article guide, Notation Quaternions for Physics and Engineering: Orientation, 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, relative attitude, error quaternion, attitude error, multiplicative error, small angle approximation, exercises, worked solutions

This object's parent.

Cross-references: noncommutative group, relation, formula, matrix, commute, representation, covariance, magnitude, Euler Angle, relative attitude, injection, norm, scalar, computation, direction cosine matrix, error quaternions, quaternion, identity, vector, relative attitude and error quaternions
There is 1 reference to this object.

This is version 2 of example of relative attitude and error quaternions, born on 2026-08-24, modified 2026-08-28.
Object id is 1108, canonical name is ExampleOfRelativeAttitudeAndErrorQuaternions.
Accessed 159 times total.

Classification:
Physics Classification02.40.Yy (Geometric mechanics )
 02.10.Hh (Rings and algebras)
 45.40.-f (Dynamics and kinematics of rigid bodies)
Pending Errata and Addenda
None.
Discussion
Style: Expand: Order:

No messages.

Interact
rate | post | correct | update request | add example | add (any)