i
i
i
i
i
i
i
i
A
Rotation with
Quaternions
It is perfectly feasible to define the orientation of an object in 3D space using
only three numbers, such as the Euler angles ( , , ). However, when we
make the jump to animation, these three values are no longer adequate to
represent the orientation of the object at a given frame and how it rotates
from that orientation to a new orientation at the next frame. Indeed, we can
represent this change by a 3 × 3 transformation matrix, but a nine-element
matrix is difficult to manipulate, and there is an easier way to achieve the
same results with only four numbers! That’s where quaternion mathematics
gets involved.
In 1843, Hamilton [1] developed the mathematics of the quaternion as
part of his attempt to find a generalization of the complex number. The
significance of the quaternion for computer graphics and animation was first
recognized by Shoemake [3]. Since then, it has become the standard way of
implementing angular interpolation.
In essence, the advantage of using quaternions in 3D computer graph-
ics work is that that interpolation between two orientations (
0
,
0
,
0
) and
(
1
,
1
,
1
) when expressed in their quaternion form is easily done utilizing
the shortest path between both of them. We recall that linear interpolation
between two position vectors gives a straight line, and in Cartesian geometry
a straight line is the shortest path between two points. When dealing with 3D
rotations, however, the shortest distance is no longer a straight line but rather
a curve. Quarternion mathematics allows us to interpolate between two ori-
entations along this shortest-distance curve. How is this possible? Essentially,
a unit quaternion represents an axis of rotation, and at the same time, an
amount of rotation about that axis.
537
i
i
i
i
i
i
i
i
538 A. Rotation with Quaternions
To make use of quaternions in VR, it is unnecessary to explore the details
of the quaternion. We are interested in using quaternions to help us achieve
angular interpolation between given orientations, and this requires that we
can interpolate between quaternions and switch back and forward between
equivalent representations of orientation, i.e., Euler angles, quaternions and
rotation matrices. In this appendix we hope to scratch the surface of this
fascinating subject and prove how useful they are in 3D animation, computer
graphics and VR.
A.1 The Quaternion
Aquaternionq is an ordered pair (w, v) of a scalar and three-dimensional
vector v with components (x, y, z). Like vectors, a unit length or normalized
quaternion must satisfy
w
2
+ x
2
+ y
2
+ z
2
= 1.
Quaternions have their own algebra with rules for addition and multipli-
cation. Addition is straightforward: add the scalar components together and
add the vector components together.
Multiplication is more interesting. Given two quaternions q
1
and q
2
the
product is the quaternion
q
1
q
2
= (w, v) = (w
1
w
2
v
1
· v
2
, w
1
v
2
+ w
2
v
1
+ v
1
× v
2
).
A conjugate quaternion to q is defined as
q = (w, v). The magnitude of
aquaternionq is determined by multiplying it with its conjugate quaternion;
that is
q
q = |q|
2
= (w
2
v · v, wv + wv + v × v).
Since the cross-product of any vector with itself is 1, this expressions simplifies
to
q
q = |q|
2
= w
2
+ |v|
2
.
Note that if q is of unit magnitude, its inverse q
1
equals its conjugate, q
1
=
q and qq = 1.
i
i
i
i
i
i
i
i
A.2. Quaternions and Rotation 539
A.2 Quaternions and Rotation
We have seen in Section 6.6.3 that the action of rotating a vector r from
one orientation to another may be expressed in terms of the application of
a transformation m atrix R which transforms r to r
= Rr, which has a new
orientation. The matrix R is independent of r and will perform the same
(relative) rotation on any other vector.
One can write R in terms of the Euler angles, i.e., as a function R(
, , ).
However, the same rotation can also be achieved by specifying R in terms of a
unit vector ˆn and a single angle
. That is, r is transformed into r
by rotating
it round ˆn through . The angle is positive when the rotation takes place in
a clockwise direction when viewed along ˆn from its base. The two equivalent
rotations may be written as
r
= R( , , )r;
r
= R
( , ˆn)r.
At first sight, it might seem difficult to appreciate that the same transforma-
tion can be achieved by specifying a single rotation round one axis as opposed
to three rotations round three or thogonal axes. It is a lso quite difficult to
imagine how (
, ˆn) might be calculated, given the more naturally intuitive
and easier to specify Euler angles ( , , ). However, there is a need for meth-
ods to switch from one representation to another.
In a number of important situations, it is necessary to use the
(
, ˆn) representation. For example, the Virtual Reality Modeling
Language (VRML) [2] uses the ( , ˆn) specification to define the
orientation adopted by an object in a virtual world.
Watt and Watt [4, p. 359] derive an expression that gives some insight
into the significance of the (
, ˆn) specification of a rotational transform by
determining Rr intermsof( , ˆn):
r
= Rr = cos r + (1 cos )(ˆn · r )ˆn + (sin ) ˆn × r. (A.1)
This expression is the vital link between rotational transformations and the
use of quaternions to represent them. To see this consider two quaternions:
1. p = (0, r), a quaternion formed by setting its scalar part to zero and its
vector part to r (the vector we wish to transform).
i
i
i
i
i
i
i
i
540 A. Rotation with Quaternions
2. q = (w, v ), an arbitrar y quaternion with unit magnitude: qq =
qq
1
= 1.
The product qpq
1
gives the quaternion
qpq
1
= (0, (w
2
(v · v)r + 2(v · r)v + 2w(v × r))). (A.2)
Since q (q = (w, v)) is an arbitrary quaternion of unit magnitude, there is
no loss of generality by substituting cos
2
for w and sin
2
ˆn for v.This
results in the following:
q = (cos
2
, sin
2
ˆn). (A.3)
Now, utilizing this new formulation for q, we can rewrite Equation (A.2).
After some simplification it can be seen that the vector part of qpq
1
is iden-
tical, term for term, with the rotation expressed by Equation (A.1).
Therefore, if we express a rotation in matrix form R(
, ˆn), its action on a
vector r is equivalent to the following four steps:
1. Promote the vector r to the quaternion p = (0, r).
2. Express matrix R(
, ˆn) as the quaternion q = (cos
2
, sin
2
ˆn).
3. Evaluate the quaternion product p
= qpq
1
.
4. Extract the transformed vector r
from the vector component of p
=
(0, r
). (Note that the scalar component of operations such as these will
always be zero.)
This isnt the end of our story of quaternions because, just a s rotational
transformations in matrix form may be combined into a single matrix, ro-
tations in quaternion form may be combined into a single quaternion by
multiplying their individual quaternion representations together. Let’s look
at a simple example to show this point. Consider two rotations R
1
and R
2
which are represented by quaternions q
1
and q
2
respectively.
By applying q
1
to the point p, we will end up at p
. By further applying
q
2
to this new point, we will be rotated to p

; that is,
p
= q
1
pq
1
1
;
p

= q
2
p
q
1
2
;
p

= q
2
(q
1
pq
1
1
)q
1
2
;
p

= (q
2
q
1
)p(q
1
1
q
1
2
).
i
i
i
i
i
i
i
i
A.2. Quaternions and Rotation 541
To simplify the expression, we can represent q
1
q
2
as the composite matrix q
c
.
And since quaternions satisfy (q
2
q
1
)
1
= q
1
1
q
1
2
,wecanwrite(q
1
1
q
1
2
) =
(q
2
q
1
)
1
. This simplifies our expression to
p

= q
c
pq
1
c
.
A.2.1 Converting Euler Angles to a Quaternion
From the Euler angles ( , , ), a quaternion that encapsulates the same in-
formation is constructed by writing quaternions for rotation of about the
z-axis, about the y -axis and about the x-axis:
q
x
=
cos
2
, sin
2
, 0, 0
,
q
y
=
cos
2
, 0, sin
2
, 0
,
q
z
=
cos
2
, 0, 0, sin
2
,
and then multiplying them together as q = q
z
q
y
q
x
. The components of q are
w = cos
2
cos
2
cos
2
+ sin
2
sin
2
sin
2
,
x = sin
2
cos
2
cos
2
cos
2
sin
2
sin
2
,
y = cos
2
sin
2
cos
2
+ sin
2
cos
2
sin
2
,
z = cos
2
cos
2
sin
2
sin
2
sin
2
cos
2
.
A.2.2 Converting a Quaternion to a Matrix
In Section 6.6.3, it was shown that a rotational transformation in matrix form
could be applied to a position vector to pivot it into a new orientation p
=
T p. A quaternion contains rotational information, but it cannot be directly
applied to a position vector in the same way that a matrix can. Therefore,
it is useful to have a method of expressing the rotational information in the
quaternion directly as a matrix, which in turn can be used to rotate position
vectors.
..................Content has been hidden....................

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