Quat Dynamics
Quat Dynamics
Quat Dynamics
Basile Graf
[email protected]
February, 2007
Abstract
We give a simple and self contained introduction to quaternions and their prac-
tical usage in dynamics. The rigid body dynamics are presented in full details.
In the appendix, some more exotic relations are given that allow to write more
complex models, for instance, the one of a satellite with inertial wheels and
expressed in a non-inertial reference frame. As it is well known, one nice ad-
vantage of quaternions over Euler angles, beside the usual arguments, is that it
allows to write down quite complex dynamics completely by hand.
Contents
1 Quaternions 3
1.1 Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Notations and Definitions . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Quaternion Product . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Quaternions and Spatial Rotations . . . . . . . . . . . . . . . . . 4
1.5 Quaternions and Rotation Velocity . . . . . . . . . . . . . . . . . 6
1.5.1 Rotation Velocity in Fixed Reference Frame ω . . . . . . 7
1.5.2 Rotation Velocity in Body Reference Frame ω ′ . . . . . . 7
1.5.3 Matrix-Product Notation for ω . . . . . . . . . . . . . . . 8
1.5.4 Matrix-Product Notation for ω ′ . . . . . . . . . . . . . . . 8
1.5.5 Rotation Matrix R . . . . . . . . . . . . . . . . . . . . . . 9
1.5.6 Ep and Gp . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5.7 One Last Relation . . . . . . . . . . . . . . . . . . . . . . 10
1.5.8 Relations Summary . . . . . . . . . . . . . . . . . . . . . 11
1.6 Rigid Body Rotational Dynamics . . . . . . . . . . . . . . . . . . 11
1.6.1 Derivatives of L . . . . . . . . . . . . . . . . . . . . . . . 12
1.6.2 Generalized Forces . . . . . . . . . . . . . . . . . . . . . . 13
1.6.3 Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
B Speed Composition 18
2
1 Quaternions
1.1 Fundamentals
Relation (1), together with associativity and distributivity is all what we will
use to derive the basic practical applications for quaternions.
i2 = j 2 = k 2 = ijk = −1 (1)
By left- and right-multiplication in the above equation, we can write
i ijk = −jk = −i
ijk k = −ij = −k
j jk = −k = ji ij j = −i = kj
i ij = −j = ik ji i = −j = −ki
This shows the product is non commutative and gives the basic multiplication
rules:
ij = k ji = −k
jk = i kj = −i (2)
ki = j ik = −j
q = q0 + q1 i + q2 j + q3 k.
However, this notation proves itself to be very unpractical. We will therefore
use two different notations:
q̄ = (q0 , −~q)
and it’s norm (a nonnegative real value) as
q
|q| = |q| = q02 + q12 + q22 + q32 .
The product of two quaternions written as pairs, as described in the next
section will be noted with ◦.
3
1.3 Quaternion Product
From the rules given in (2), we may write the product of q with p.
(q0 + q1 i + q2 j + q3 k)(p0 + p1 i + p2 j + p3 k) =
p0 q0 + q0 p1 i + q0 p2 j + q0 p3 k
+ q1 p0 i + q1 p1 ii + q1 p2 ij + q1 p3 ik
+ q2 p0 j + q2 p1 ji + q2 p2 jj + q2 p3 jk
+ q3 p0 k + q3 p1 ki + q3 p2 kj + q3 p3 kk =
p0 q0 − q1 p1 − q2 p2 − q3 p3
+ (q1 p0 + q0 p1 + q2 p3 − q3 p2 ) i
+ (q2 p0 + q0 p2 + q3 p1 − q1 p3 ) j
+ (q3 p0 + q0 p3 + q1 p2 − q2 p1 ) k
q ◦ p = p̄ ◦ q̄ (6)
that is
|q ◦ p| = |q||p|. (7)
(~u × ~v ) × w
~ = (~u · w)~
~ v − (~v · w)~
~ u
ϕ 1 − cos ϕ ϕ 1 + cos ϕ
sin2 = cos2 = .
2 2 2 2
From now on, q will generally represent a normed quaternion (|q| = 1)
involved in a rotation. Let’s now place a vector ~x ∈ R3 in the imaginary part
of a quaternion x and see what happens with it in the following relation
4
x′ = q̄ ◦ x ◦ q x = (0, ~x) q = (q0 , ~q).
Using (3)
Re x′ = (~
q · ~x)q0 − q0 (~x · ~q) − (~q × ~x) · ~q = 0
⇒ x′ = (0, ~x′ ),
′
~ x = ~x′
Im
= (~ q + q02 ~x − q0 (~q × ~x) + q0 (~x × ~q) − (~q × ~x) × ~q
q · ~x)~
= (~ q + q02 ~x + 2q0 (~x × ~q) − (~q × ~x) × ~q
q · ~x)~
= (~ q + q02 ~x + 2q0 (~x × ~q) − (~q · ~q)~x + (~x · ~q)~q
q · ~x)~
= 2(~ q + q02 ~x + 2q0 (~x × ~q) − (~q · ~q)~x.
q · ~x)~
p
A valid normed quaternion (|q| = (q02 + q12 + q22 + q32 ) = 1) would be
ϕ ϕ
q = (q0 , ~
q ) = (cos , sin ~n) |~n| = 1.
2 2
In this case, ~x′ becomes
ϕ ϕ ϕ ϕ ϕ
~x′ = 2 sin2 (~n · ~x)~n + cos2 ~x + 2 cos sin (~x × ~n) − sin2 ~x
2 2 2 2 2
= (1 − cos ϕ)(~n · ~x)~n + cos ϕ ~x + sin ϕ (~x × ~n).
This last relation is the formula for a rotation by an angle ϕ around a normed
axis vector ~n, as can be shown with the following figure as follows:
~v3
~v2
· ~n)~n ϕ
(~x
~x′ ~v1
~n
~x
0
5
~v2 = cos ϕ ~v1 + sin ϕ ~v3
~v1 = ~x − (~x · ~n)~n
~v3 = ~v1 × ~n
= (~x − (~x · ~n)~n) × ~n
= (~x × ~n) − (~x · ~n) ~n × ~n}
| {z
~0
Moreover
x′ = q̄ ◦ x ◦ q
q ◦ x′ ◦ q̄ = q ◦ q̄ ◦x ◦ q ◦ q̄ .
|{z} |{z}
(1,~0) (1,~0)
Thus we have the relations for the rotation and its inverse
x′ = q̄ ◦ x ◦ q x = q ◦ x′ ◦ q̄ . (8)
x = q ◦ x′ ◦ q̄ x′ = q̄ ◦ x ◦ q.
Applying the time derivative to x = (0, ~x), with x′ = (0, ~x′ ) and ~x˙ ′ = ~0, we
get
ẋ = q̇ ◦ x′ ◦ q̄ + q ◦ x′ ◦ q̄˙
ẋ = q̇ ◦ q̄ ◦ x ◦ q ◦ q̄ + q ◦ q̄ ◦x ◦ q ◦ q̄˙
|{z} |{z}
Id Id
ẋ = q̇ ◦ q̄ ◦ x + x ◦ q ◦ q̄˙ (9)
and from (3)
6
q̇ ◦ q̄ = (q˙0 q0 + ~q˙ · ~q, −q˙0 ~q + q0 ~q˙ − ~q˙ × ~q)
| {z }
~
ẋ = (0, ~ν ) ◦ x − x ◦ (0, −ν)
~x˙ = ~ν × ~x − ~x × ~ν = 2~ν × ~x
and from (7)
|~x˙ | = |2~ν ||~x| ⇒ ~ν ⊥~x
If ~x undergoes a pure rotation, we know that
ω ◦ q = 2q̇ ◦ q̄ ◦ q ⇒ ω ◦ q = 2q̇
|{z}
Id
q̇ = 21 ω ◦ q . (12)
ω ′ = q̄ ◦ ω ◦ q with ω = 2q̇ ◦ q̄
′
⇒ ω = 2q̄ ◦ q̇ ◦ q̄ ◦ q
|{z}
Id
ω ′ = 2q̄ ◦ q̇ . (13)
And left-multiplication by q
q ◦ ω ′ = 2 q ◦ q̄ ◦q̇ = 2q̇
|{z}
Id
1
q̇ = 2q ◦ ω′ . (14)
7
1.5.3 Matrix-Product Notation for ω
From
ω = 2q̇ ◦ q̄
and using (3)
~ 2q̇ ◦ q̄
ω = Im
~ = 2(−q˙0 ~q+q0 ~q˙−~q˙ × ~q)
q˙0
−q1 q0 −q3 q2 q˙1
= 2 −q2 q3 q0 −q1 q˙2
−q3 −q2 q1 q0
| {z } q˙3
E
~ω = 2E q̇.
Changing the sign and inverting the cross product allows to make an other
identification
~ = −2Ėq.
ω
So the rotation velocity vector in the fixed reference frame can be written as
~ω = 2E q̇ = −2Ėq . (15)
And from
1
q̇ = ω◦q ω = (0, ~ω) ⇒ ω0 = 0
2
one can similarly find
1 (−~ω · ~q) 1
q̇ = = E T ~ω
2 (q0 ω
~ + ~ω × ~q) 2
q̇ = 21 E T ~ω . (16)
ω ′ = 2q̄ ◦ q̇
and using (3)
8
ω~′ = Im
~ 2q̄ ◦ q̇ = 2(q0 ~q˙−q˙0 ~q−~q × ~q˙)
q˙0
−q1 q0 q3 −q2 q˙1
= 2 −q2 −q3 q0 q1
q˙2
−q3 q2 −q1 q0
| {z } q˙3
G
ω~′ = 2Gq̇.
Changing the sign and inverting the cross product allows to make an other
identification
ω~′ = −2Ġq.
So the rotation velocity vector in the body reference frame can be written as
q̇ = 12 GT ω~′ . (18)
ω = 2E q̇ = −2Ėq
~ ω~′ = 2Gq̇ = −2Ġq
1 1
q̇ = E T ~
ω q̇ = GT ω~′
2 2
So we can write
ω = 2E q̇
~ ω~′ = 2Gq̇
1 1
= 2E( E T ~
ω) = 2G( GT ω~′ )
2 2
= EE T ~ω = GGT ω~′
⇒ EE T = Id . ⇒ GGT = Id .
9
And by mixing both sides
1
ω~′ = 2Gq̇ = 2G( E T ~ω) = GE T ~ω
2
1 T ~′
ω = 2E q̇ = 2E( G ω ) = EGT ω~′ .
~
2
We shall now remember that ~ω is a vector in the fixed reference frame and
~ ′ is the same vector in the body reference frame, that is ~ω = Rω~′ . By
that ω
comparing with the previous two results, we find
1.5.6 Ep and Gp
From the identifications made in sections 1.5.3 and 1.5.4, we can see that the
general meaning the product of E and G with any quaternion p is
~ p ◦ q̄
Ep = Im ~ q̄ ◦ p .
Gp = Im (20)
And from
Eq = ~0 Gq = ~0 .
= 2q̄ ◦ q̇ ◦ v
= 2(q0 q˙0 +~ q˙, q0 ~q˙−q˙0 ~q−~q × ~q˙) ◦ v = 2q̄ ◦ (q˙0 v0 −~q˙ · ~v , q˙0~v +v0 ~q˙+~q˙ × ~v )
q·~
q0 q1 q2 q3 q˙0 −q ˙ 1 −q ˙ 2 −q ˙3 0
˙
q˙1 q˙0 −q3 q˙2 v1
−q1 q0 q3 −q2
≡ 2 ˙
−q2 −q3 q0 q1 q˙2 q˙3 q˙0 −q1 v2
−q3 q2 −q1 q0 ˙
q˙3 −q2 q˙1 q˙0 v3
T
q 0 ~ ′
−ω · ~v
=2 q̇ ĠT =
G ~v ω~′ × ~v
⇒ 2GĠT ~v = Ω′~v = ω~′ × ~v .
10
Comparing with (17), we conclude that
ω = (0, ~
ω) = 2q̇◦ q̄ ω ′ = (0, ~ω ′ ) = 2q̄ ◦ q̇ ~ω = 2E q̇ = −2Ėq ~ω ′ = 2Gq̇ = −2Ġq
q̇ = 12 ω ◦ q q̇ = 21 q ◦ ω ′ q̇ = 12 E T ~ω q̇ = 21 GT ~ω ′
EE T = Id GGT = Id
q ◦ q̄ = q̄ ◦ q = (|q|, ~0) Eq = ~0 Gq = ~0
Ω′ = 2GĠT
(0, ~ω ) ◦ (0, ~v ) =
= −2ĠGT
(−ω~′ · ~v , ω~′ × ~v )
Ω ~v = ω~′ × ~v
′
−q1 q0 −q3 q2 −q1 q0 q3 −q2
E = −q2 q3 q0 −q1 G = −q2 −q3 q0 q1
−q3 −q2 q1 q0 −q3 q2 −q1 q0
11
d ∂L ∂L ∂C
− = Fq + λ . (23)
dt ∂ q̇ ∂q ∂q
Fq is the 4-vector of generalized forces which will be expressed in term of
applied torque later. λ is the Lagrangian multiplier used to satisfy the constraint
C.
1.6.1 Derivatives of L
Note the following reminder
∂Ax = A
∂x
∂aT x = ∂xT a = a
∂x ∂x
∂xT Ax = (AT + A)x if A=A T
= 2Ax
∂x
(written as column vectors)
(AB)T = B T AT .
We will now derive each term of the left side of (23). First, let us rewrite L
in two different ways
1 ′T ′
L= ω J~
~ ω = 2(Gq̇)T J(Gq̇) = 2(Ġq)T J(Ġq)
2
and grouping around J
1 ′T ′
L= ω = 2q̇T (GT JG)q̇ = 2qT (ĠT J Ġ)q.
ω J~
~
2
Because J is symmetric, (GT JG) and (ĠT J Ġ) are also symmetric. So we
have
∂L
= 4ĠT J Ġq = 2ĠT J (2Ġq) = −2ĠT J~ω ′ , (24)
∂q | {z }
−~
ω′
∂L
= 4GT JGq̇ = 2GT J (2Gq̇) = 2GT J~ω ′
∂ q̇ | {z }
ω
~′
and
d ∂L d
= (2GT J~ω ′ ) = 2ĠT J~ω ′ + 2GT J ~ω˙ ′ . (25)
dt ∂ q̇ dt
12
1.6.2 Generalized Forces
A way to find the generalized force Fc relative to the coordinates c is to identify
it in
δW = Fc · δc.
(A simple example is the case of a pure translation δ~x of a particle, on which
a force F~ is applied. The work is then δW = F~x · δ~x = F~ · δ~x. So the generalized
force F~x is simply F~ in this case.)
q + δq = q ◦ qδ
|q| = 1 |qδ | = 1 |δq| ≪ 1.
We do not need to consider the fact that the variation δq has to preserve the
norm of q, because it will automatically be satisfied by introducing a constraint
in the Lagrange formulation.
q + δq = q ◦ qδ
q̄ ◦ q +q̄ ◦ δq = q̄ ◦ q ◦qδ
|{z} |{z}
(1,~0) (1,~0)
| {z }
qδ
~ q̄ ◦ δq = sin δϕ ~n ≈ δϕ ~n
~ qδ = Im
Im
2 2
13
comparing with (26)
~ q̄ ◦ δq · T~ ′
⇒ δW = 2 Im
and from (20)
~ q̄ ◦ δq = Gδq
Im
⇒ δW = 2(Gδq) · T~ ′ = 2T~ ′T (Gδq) = 2(GT T~ ′ )T δq = 2(GT T~ ′ ) ·δq
| {z }
Fq
⇒ Fq = 2GT T~ ′ . (28)
1.6.3 Dynamics
We have now everything to write the dynamics
d ∂L ∂L ∂C
− = Fq + λ
dt ∂ q̇ ∂q ∂q
T ′ T ˙′ T ~′
4Ġ J~ω + 2G J ~ω = 2G T + λq.
Left-multiplying by G
4G ω ′ + 2 |GG
ĠT} J~ T ˙′ T ~′
| {z {z } J ~ω = 2 |GG
{z } T + λ |{z}
Gq
2Ω′ Id Id ~0
′ ′
Ω J~ω + J ~ω = T ˙′ ~′
~ ′ × J~ω ′ + J ~ω˙ ′ = T~ ′
ω
J ~ω˙ ′ = T~ ′ − ω
~ ′ × J~ω ′ .
This last relation is nothing else than the Euler equation of motion for ro-
tating body. Together with (18) we obtain the complete dynamics
~˙ ′
ω = J −1 T~ ′ − J −1 (~ω ′ × J~ω ′ )
(29)
1 T ′
q̇ = 2G ~
ω.
14
A Derivatives and Quaternions
A.1 Quadratic Form Derivative by a Quaternion
In order to be able to derive the Lagrangian by the components of q for a
non-inertial quaternion model, one needs to perform things like
∂(~v T Rw)
~ ∂(~v T RT w)
~
,
∂q ∂q
and also
The vector obtained is quite ugly but one can see that it is linear in q, it
can thus be rewritten in a matrix-vector product:
0 10 1
v1 w1 + v2 w2 + v3 w3 v3 w2 − v2 w3 −v3 w1 + v1 w3 v2 w1 − v1 w2 q0
B CB C
B
B v3 w2 − v2 w3 v1 w1 − v2 w2 − v3 w3 v1 w2 + v2 w1 v1 w3 + v3 w1 C B q1
CB
C
C
2B CB C
B −v3 w1 + v1 w3 v1 w2 + v2 w1 v2 w2 − v1 w1 − v3 w3 v2 w3 + v3 w2 C B q2 C
@ A@ A
v2 w1 − v1 w2 v1 w3 + v3 w1 v2 w3 + v3 w2 v3 w3 − v1 w1 − v2 w2 q3
| {z }
∆[~v , w]
~
15
By careful inspection of ∆[~v , w],
~ we can identify a structure in the matrix
that allows a compact notation
w~ · ~v (w~ × ~v )T
∆[~v , w]
~ = . (30)
~ × ~v w~
w ~ v T + ~v w
~T − w ~ · ~v I3
That is
∂(~v T Rw)
~
= 2∆[~v , w]q
~ (31)
∂q
And because ~v T RT w ~ T R~v we also have
~ =w
∂(~v T RT w)
~
= 2∆[w,
~ ~v ]q (32)
∂q
1 ∂ T T
1 T ∂R T 1 T ∂RT
~u RJR ~u = ~u JR ~u + ~u RJ ~u
2 ∂q 2 ∂qi 2 ∂qi
i i
∂R
= ~uT JRT ~u .
∂qi i
Hence
1 ∂
~uT RJRT ~u = 2∆[~u, JRT ~u]q (33)
2 ∂q
A.1.3 Properties
By looking at (30), one may note the following relations
∆[~v1 + ~v2 , w]
~ = ∆[~v1 , w]
~ + ∆[~v2 , w]
~ (34)
∆[~v , w
~1 + w
~ 2 ] = ∆[~v , w
~ 1 ] + ∆[~v , w
~ 2] (35)
n
X m
X n X
X m
∆ ~vi , ~j =
w ∆[~vi , w
~j] (36)
i=1 j=1 i=1 j=1
∆[α~v , β w]
~ = αβ∆[~v , w]
~ (37)
16
A.2 Time Derivative of R
First note that by identification, one can verify that
GT G = E T E = I4 − qqT (38)
and
~ ′ = 2Gq̇ = −2Ġq.
ω
Now observe
Ω′ RT = 2GĠT GE T
= −2ĠGT GE T
= −2Ġ(I4 − qqT )E T
= −2ĠE T − 2Ġq qT E T
| {z }
(Eq)T =~0
T T
= −2ĠE = −Ṙ .
17
B Speed Composition
Let be three referentials each designed by 0, 1 and 2. Referential 0 is inertial,
referential 1 is a rotating one and 2 is a body fixed referential.
The same vector ~x can be expressed in any of these referentials; when expressed
in 0, we will notate it as ~x0 , when expressed in 1 it will be noted ~x1 and ~x2 in
referential 2. We will also write xi the quaternion (0, ~xi ).
Moreover, three quaternions are defined: q01 describes relative attitude of refer-
ential 1 with respect to referential 0, q12 describes relative attitude of referential
2 with respect to referential 1 and q02 describes relative attitude of referential
2 with respect to referential 0.
q12
q01
2
0
q02
So we may write
x0 = q01 ◦ x1 ◦ q̄01 = q01 ◦ q12 ◦ x2 ◦ q̄12 ◦ q̄01 = (q01 ◦ q12 ) ◦ x2 ◦ (q01 ◦ q12 )
we can identify q02
18
2
ω02 = 2q̄02 ◦ q̇02
= 2(q̄12 ◦ q̄01 ) ◦ (q̇01 ◦ q12 + q01 ◦ q̇12 )
= 2q̄12 ◦ q̄01 ◦ q̇01 ◦ q12 + 2q̄12 ◦ q̄01 ◦ q01 ◦q̇12
| {z }
Id
= q̄12 ◦ (2q̄01 ◦ q̇01 ) ◦q12 + 2q̄12 ◦ q̇12
| {z } | {z }
1 2
ω12
ω01
1 2
= q̄12 ◦ ω01 ◦ q12 + ω12
2 2
= ω01 + ω12 .
That is, we can add consecutive rotation speeds if they are expressed in the
same referential.
2
In the case of the Cubsat, ~ω02 is the satellite’s rotation velocity ~ω ′ expressed in
′
body coordinates in the inertial referential model; we will note it ~ωInertial here.
2 ′
On the other hand, ~ ω12 is the satellite’s rotation velocity ω~ expressed in body
coordinates in the non-inertial referential model (i.e. in orbital reference frame,
′
ORF); we will note it ~ωN onInertial .
1 2
ω01 is the ORF rotation velocity expressed in the ORF, that is ~ωo , while ~ω01
~
is the same vector, transformed in the body referential. This transformation is
performed by RT from the non-inertial model (q̄12 in the above developement).
In other words, we can link the ~ω ′ vector from both inertial and non-inertial
formulations (models) with
′ T ′
ω
~ Inertial = RN ωo + ~ωN
onInertial ~ onInertial . (42)
This is the speed to be used in computing the kinetic energy for the non-
inertial model.
19
C Euler Angles to Quaternions
Three rotations by the Euler angles around each axis can be written as
cos (ψ) − sin (ψ) 0
sin (ψ)
Rψ = cos (ψ) 0
0 0 1
cos (θ) 0 sin (θ)
Rθ =
0 1 0
− sin (θ) 0 cos (θ)
1 0 0
0
Rφ = cos (φ) − sin (φ)
0 sin (φ) cos (φ)
R = Rφ Rθ Rψ .
1
1
1
cos φ 2 cos 2 θ cos 2 ψ
sin 1 φ 0 0
2
qφ = qθ = qψ = .
0 sin 1 θ 0
2
1
0 0 sin 2 ψ
20
1 1
1
1
1
1
cos φ cos
2 2 θ cos 2 ψ − sin 2 φ sin 2 θ sin 2 ψ
cos 1 ψ cos 1 1 1 1 1
2 2 θ sin 2 φ + cos 2 φ sin 2 θ sin 2 ψ
q = qφ ◦qθ ◦qψ = .
cos 1 ψ cos 1 1 1 1 1
2 φ sin 2 θ − cos 2 θ sin 2 φ sin 2 ψ
2
cos 12 φ cos 1
2 θ sin
1
2 ψ + cos
1
2 ψ sin
1
2 φ sin
1
2 θ
Note: that this result depends on the convention used in the order and choice
of the Euler angles and rotation axes! [5]
21
References
[1] Quaternion, Finite Rotation and Euler Parameters
Arend L. Schwab
http://tam.cornell.edu/˜als93/quaternion.pdf
[2] Quaternion based dynamics - Single Turbine Aircraft - Lagrange and Hamil-
tonian approaches
S. Gros
LA, EPFL.
[3] Classical Mechanics
Herbert Goldstein.
[4] Lagrangian Dynamics
Dare A. Wells
Schaum’s Outline Series.
[5] http://www.mathworks.com/access/helpdesk/help/toolbox/aeroblks/index.html?
/access/helpdesk/help/toolbox/aeroblks/euleranglestoquaternions.html
22