i
i
i
i
i
i
i
i
4.3. Quaternions 73
Multiplication :
ˆ
q
ˆ
r =(iq
x
+ jq
y
+ kq
z
+ q
w
)(ir
x
+ jr
y
+ kr
z
+ r
w
)
= i(q
y
r
z
q
z
r
y
+ r
w
q
x
+ q
w
r
x
)
+ j(q
z
r
x
q
x
r
z
+ r
w
q
y
+ q
w
r
y
)
+ k(q
x
r
y
q
y
r
x
+ r
w
q
z
+ q
w
r
z
)
+ q
w
r
w
q
x
r
x
q
y
r
y
q
z
r
z
=
=(q
v
× r
v
+ r
w
q
v
+ q
w
r
v
,q
w
r
w
q
v
·r
v
).
(4.29)
As can be seen in this equation, we use both the cross product and the
dot product to compute the multiplication of two quaternions.
10
Along
with the definition of the quaternion, the definitions of addition, conjugate,
norm, and an identity are needed:
Addition :
ˆ
q +
ˆ
r =(q
v
,q
w
)+(r
v
,r
w
)=(q
v
+ r
v
,q
w
+ r
w
).
Conjugate :
ˆ
q
=(q
v
,q
w
)
=(q
v
,q
w
).
Norm : n(
ˆ
q)=
ˆ
q
ˆ
q
=
ˆ
q
ˆ
q =
q
v
· q
v
+ q
2
w
=
q
2
x
+ q
2
y
+ q
2
z
+ q
2
w
.
Identity :
ˆ
i =(0, 1).
(4.30)
When n(
ˆ
q)=
ˆ
q
ˆ
q
is simplified (result shown above), the imaginary parts
cancel out and only a real part remains. The norm is sometimes denoted
||
ˆ
q|| = n(
ˆ
q) [808]. A consequence of the above is that a multiplicative
inverse, denoted by
ˆ
q
1
, can be derived. The equation
ˆ
q
1
ˆ
q =
ˆ
q
ˆ
q
1
=1
must hold for the inverse (as is common for a multiplicative inverse). We
derive a formula from the definition of the norm:
n(
ˆ
q)
2
=
ˆ
q
ˆ
q
⇐⇒ (4.31)
ˆ
q
ˆ
q
n(
ˆ
q)
2
=1.
This gives the multiplicative inverse as shown below:
Inverse :
ˆ
q
1
=
1
n(
ˆ
q)
2
ˆ
q
.
(4.32)
The formula for the inverse uses scalar multiplication, which is an operation
derived from the multiplication seen in Equation 4.29: s
ˆ
q =(0,s)(q
v
,q
w
)
10
In fact, the quaternion multiplication is the origin of both the dot product and the
cross product.
i
i
i
i
i
i
i
i
74 4. Transforms
=(sq
v
,sq
w
), and
ˆ
qs =(q
v
,q
w
)(0,s)=(sq
v
,sq
w
), which means that
scalar multiplication is commutative: s
ˆ
q =
ˆ
qs =(sq
v
,sq
w
).
The following collection of rules are simple to derive from the definitions:
Conjugate rules:
(
ˆ
q
)
=
ˆ
q,
(
ˆ
q +
ˆ
r)
=
ˆ
q
+
ˆ
r
, (4.33)
(
ˆ
q
ˆ
r)
=
ˆ
r
ˆ
q
.
Norm rules:
n(
ˆ
q
)=n(
ˆ
q),
(4.34)
n(
ˆ
q
ˆ
r)=n(
ˆ
q)n(
ˆ
r).
Laws of Multiplication:
Linearity:
ˆ
p(s
ˆ
q + t
ˆ
r)=s
ˆ
p
ˆ
q + t
ˆ
p
ˆ
r,
(4.35)
(s
ˆ
p + t
ˆ
q)
ˆ
r = s
ˆ
p
ˆ
r + t
ˆ
q
ˆ
r.
Associativity:
ˆ
p(
ˆ
q
ˆ
r)=(
ˆ
p
ˆ
q)
ˆ
r.
A unit quaternion,
ˆ
q =(q
v
,q
w
), is such that n(
ˆ
q) = 1. From this it
follows that
ˆ
q may be written as
ˆ
q =(sinφu
q
, cos φ)=sinφu
q
+cosφ, (4.36)
for some three-dimensional vector u
q
, such that ||u
q
|| = 1, because
n(
ˆ
q)=n(sin φu
q
, cos φ)=
sin
2
φ(u
q
· u
q
)+cos
2
φ
=
sin
2
φ +cos
2
φ = 1 (4.37)
if and only if u
q
· u
q
=1=||u
q
||
2
. As will be seen in the next section,
unit quaternions are perfectly suited for creating rotations and orientations
in a most efficient way. But before that, some extra operations will be
introduced for unit quaternions.
For complex numbers, a two-dimensional unit vector can be written as
cos φ + i sin φ = e
. The equivalent for quaternions is
ˆ
q =sinφu
q
+cosφ = e
φu
q
. (4.38)
The log and the power functions for unit quaternions follow from Equa-
tion 4.38:
Logarithm :log(
ˆ
q)=log(e
φu
q
)=φu
q
,
Power :
ˆ
q
t
=(sinφu
q
+cosφ)
t
= e
φtu
q
=sin(φt)u
q
+cos(φt).
(4.39)
i
i
i
i
i
i
i
i
4.3. Quaternions 75
Figure 4.8. Illustration of the rotation transform represented by a unit quaternion,
ˆ
q =(sinφu
q
, cos φ). The transform rotates 2φ radians around the axis u
q
.
4.3.2 Quaternion Transforms
We will now study a subclass of the quaternion set, namely those of unit
length, called unit quaternions. The most important fact about unit quater-
nions is that they can represent any three-dimensional rotation, and that
this representation is extremely compact and simple.
Now we will describe what makes unit quaternions so useful for rotations
and orientations. First, put the four coordinates of a point or vector p =
(p
x
p
y
p
z
p
w
)
T
into the components of a quaternion
ˆ
p, and assume that
we have a unit quaternion
ˆ
q =(sinφu
q
, cos φ). Then
ˆ
q
ˆ
p
ˆ
q
1
(4.40)
rotates
ˆ
p (and thus the point p) around the axis u
q
by an angle 2φ.Note
that since
ˆ
q is a unit quaternion,
ˆ
q
1
=
ˆ
q
. This rotation, which clearly
can be used to rotate around any axis, is illustrated in Figure 4.8.
Any nonzero real multiple of
ˆ
q also represents the same transform,
which means that
ˆ
q and
ˆ
q represent the same rotation. That is, negating
the axis, u
q
, and the real part, q
w
, creates a quaternion that rotates exactly
as the original quaternion does. It also means that the extraction of a
quaternion from a matrix can return either
ˆ
q or
ˆ
q.
Given two unit quaternions,
ˆ
q and
ˆ
r, the concatenation of first applying
ˆ
q and then
ˆ
r to a quaternion,
ˆ
p (which can be interpreted as a point p),
is given by Equation 4.41:
ˆ
r(
ˆ
q
ˆ
p
ˆ
q
)
ˆ
r
=(
ˆ
r
ˆ
q)
ˆ
p(
ˆ
r
ˆ
q)
=
ˆ
c
ˆ
p
ˆ
c
. (4.41)
Here,
ˆ
c =
ˆ
r
ˆ
q is the unit quaternion representing the concatenation of the
unit quaternions
ˆ
q and
ˆ
r.
i
i
i
i
i
i
i
i
76 4. Transforms
Matrix Conversion
Since some systems have matrix multiplication implemented in hardware
and the fact that matrix multiplication is more efficient than Equation 4.40,
we need conversion methods for transforming a quaternion into a matrix
and vice versa. A quaternion,
ˆ
q, can be converted into a matrix M
q
,as
expressed in Equation 4.42 [1176, 1177]:
M
q
=
1 s(q
2
y
+ q
2
z
) s(q
x
q
y
q
w
q
z
) s(q
x
q
z
+ q
w
q
y
)0
s(q
x
q
y
+ q
w
q
z
)1 s(q
2
x
+ q
2
z
) s(q
y
q
z
q
w
q
x
)0
s(q
x
q
z
q
w
q
y
) s(q
y
q
z
+ q
w
q
x
)1 s(q
2
x
+ q
2
y
)0
0001
. (4.42)
Here, the scalar is s =2/n(
ˆ
q). For unit quaternions, this simplifies to
M
q
=
1 2(q
2
y
+ q
2
z
)2(q
x
q
y
q
w
q
z
)2(q
x
q
z
+ q
w
q
y
)0
2(q
x
q
y
+ q
w
q
z
)1 2(q
2
x
+ q
2
z
)2(q
y
q
z
q
w
q
x
)0
2(q
x
q
z
q
w
q
y
)2(q
y
q
z
+ q
w
q
x
)1 2(q
2
x
+ q
2
y
)0
0001
. (4.43)
Once the quaternion is constructed, no trigonometric functions need to be
computed, so the conversion process is efficient in practice.
The reverse conversion, from an orthogonal matrix, M
q
, into a unit
quaternion,
ˆ
q, is a bit more involved. Key to this process are the following
differences made from the matrix in Equation 4.43:
m
q
21
m
q
12
=4q
w
q
x
,
m
q
02
m
q
20
=4q
w
q
y
,
m
q
10
m
q
01
=4q
w
q
z
.
(4.44)
The implication of these equations is that if q
w
is known, the values of the
vector v
q
can be computed, and thus
ˆ
q derived. The trace (see page 898)
of M
q
is calculated by
tr(M
q
)=4 2s(q
2
x
+ q
2
y
+ q
2
z
)=4
1
q
2
x
+ q
2
y
+ q
2
z
q
2
x
+ q
2
y
+ q
2
z
+ q
2
w
=
4q
2
w
q
2
x
+ q
2
y
+ q
2
z
+ q
2
w
=
4q
2
w
n(
ˆ
q)
.
(4.45)
This result yields the following conversion for a unit quaternion:
q
w
=
1
2
tr(M
q
),q
x
=
m
q
21
m
q
12
4q
w
,
q
y
=
m
q
02
m
q
20
4q
w
,q
z
=
m
q
10
m
q
01
4q
w
.
(4.46)
i
i
i
i
i
i
i
i
4.3. Quaternions 77
To have a numerically stable routine [1177], divisions by small numbers
should be avoided. Therefore, first set t = q
2
w
q
2
x
q
2
y
q
2
z
,fromwhichit
follows that
m
00
= t +2q
2
x
,
m
11
= t +2q
2
y
,
m
22
= t +2q
2
z
,
u = m
00
+ m
11
+ m
22
= t +2q
2
w
,
(4.47)
which in turn implies that the largest of m
00
, m
11
, m
22
,andu determine
which of q
x
, q
y
, q
z
,andq
w
is largest. If q
w
is largest, then Equation 4.46 is
used to derive the quaternion. Otherwise, we note that the following holds:
4q
2
x
=+m
00
m
11
m
22
+ m
33
,
4q
2
y
= m
00
+ m
11
m
22
+ m
33
,
4q
2
z
= m
00
m
11
+ m
22
+ m
33
,
4q
2
w
=tr(M
q
).
(4.48)
The appropriate equation of the ones above is then used to compute the
largest of q
x
, q
y
,andq
z
, after which Equation 4.44 is used to calculate the
remaining components of
ˆ
q. Luckily, there is code for this—see the Further
Reading and Resources at the end of this chapter.
Spherical Linear Interpolation
Spherical linear interpolation is an operation that, given two unit quater-
nions,
ˆ
q and
ˆ
r, and a parameter t [0, 1], computes an interpolated quater-
nion. This is useful for animating objects, for example. It is not as useful
for interpolating camera orientations, as the camera’s “up” vector can be-
come tilted during the interpolation, usually a disturbing effect [349].
The algebraic form of this operation is expressed by the composite
quaternion,
ˆ
s,below:
ˆ
s(
ˆ
q,
ˆ
r,t)=(
ˆ
r
ˆ
q
1
)
t
ˆ
q. (4.49)
However, for software implementations, the following form, where slerp
stands for spherical linear interpolation, is much more appropriate:
ˆ
s(
ˆ
q,
ˆ
r,t)=slerp(
ˆ
q,
ˆ
r,t)=
sin(φ(1 t))
sin φ
ˆ
q +
sin(φt)
sin φ
ˆ
r. (4.50)
To compute φ, which is needed in this equation, the following fact can
be used: cosφ = q
x
r
x
+ q
y
r
y
+ q
z
r
z
+ q
w
r
w
[224]. For t [0, 1], the
slerp function computes (unique
11
) interpolated quaternions that together
11
If and only if
ˆ
q and
ˆ
r are not opposite.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset