i
i
i
i
i
i
i
i
11.2. Moving and Rotating in 3D 265
hardware, our software needs to extrapolate the position of our aircraft every
one hundredth of a second until the next position, P
i+3
, is available from the
hardware.
Again, we may use Equation (11.1) to determine the position p at any
time greater than t. Thus we try to predict how the spline will behave up
until our system is updated with the actual position. This may or may not
be the same as our extrapolated position. Typically, parameterization by time
and extrapolation can lead to a small error in predicted position. For example,
the point labeled P
actual
in Figure 11.2 is the actual position of the next point
along the true path, but it lies slightly off the predicted curve.
So we need to recalculate the equation of the spline based on this current
actual position and its previous three actual positions. Thus, P
i
becomes P
i−1
and so on. Using the four new control positions, we recompute the spline,
and this new spline will then be used to predict the next position at a given
time slice. And so the procedure continues.
It is also worth noting at this stage that whilst spline extrapolation is not
without error, linear extrapolation is usually much more error-prone. For the
example in Figure 11.2, if linear extrapolation of the positions P
i+1
and P
i+2
is used to predict the new position at time t, the associated positional error is
much greater than with spline interpolation.
11.2.2 Rotating Smoothly
In this section, we turn our attention to interpolating angles of orientation.
Angles cannot be interpolated in the same way as position coordinates are in-
terpolated. For one thing they are periodic in the interval [0, −2
]. It is now
generally agreed that the best way to obtain smooth angular interpolation is
by using quaternions. Appendix A provides the background on quaternions.
It gives algorithms for converting between Euler angles, quaternions and rota-
tion matrices, and defines the function specifically for solving the problem of
orientation tweening; that is, the slerp() function. It also dem onstrates how to
calculate the transformation matrix used to set the orientation for an object or
direction of view T
a
k
at time t
k
, obtained by interpolation of the orientations
at times t
l
and t
m
.
T
a
k
cannot be obtained by directly interpolating the matrices express-
ing the orientation at times t
l
and t
m
(see Section A.2). At times t
l
and t
m
,
the matrices T
a
l
and T
a
m
are actually determined from the known values
of (
l
,
l
,
l
) and (
m
,
m
,
m
) respectively. Therefore, whilst it may not be
possible to interpolate matrices, it is possible to interpolate a quaternion asso-