Interpolation and Basic Techniques
3.3 Interpolation of Rotations Represented by Quaternions
Interpolation of Rotations Represented by Quaternions 97
(Eq. 3.21)
(Eq. 3.22)
(Eq. 3.23)
If there are the same number of given data points as there are unknown control points, 2 ≤ k ≤ n + 1 = j, then N is square and the defining control vertices can be solved by inverting the matrix, as in Equation 3.24.
(Eq. 3.24)
The resulting curve is smooth but can sometimes produce unwanted wiggles.
Specifying fewer control points (2 ≤ k ≤ n + 1 < j) can remove these wiggles but N is no longer square. To solve the matrix equation, the pseudoinverse of N must be used, as in Equation 3.25.
(Eq. 3.25)
98 3: Interpolation and Basic Techniques
Given two orientations represented by unit quaternions, intermediate orienta- tions can be produced by linearly interpolating from the first to the second. These orientations can be viewed as four-dimensional points on a straight-line path from the first quaternion to the second quaternion. Simple equal-interval, linear inter- polation between the two quaternions will not produce a constant speed rotation because the unit quaternions to which the intermediate orientations map will not produce equally spaced intervals on the unit sphere. Figure 3.22 shows the analo- gous effect when interpolating a straight-line path between points on a 2D circle.
Intermediate orientations representing constant-speed rotation can be calcu- lated by interpolating directly on the surface of the unit sphere, specifically along the great arc between the two quaternion points. A quaternion, [s, v], and its nega- tion, [–s, –v], represent the same orientation. Interpolation from one orientation, represented by the quaternion q1, to another orientation, represented by the quaternion q2, can also be carried out from q1to –q2. The difference is that one interpolation path will be longer than the other. Usually, the shorter path is the more desirable because it represents the more direct way to get from one orienta- tion to the other. The shorter path is the one indicated by the smaller angle between the 4D quaternion vectors. This can be determined by using the 4D dot product of the quaternions to compute the cosine of the angle between q1 and q2 (Equation 3.26). If the cosine is positive, then the path from q1 to q2 is shorter;
otherwise the path from q1 to –q2 is shorter (Figure 3.23).
Figure 3.22 Equally spaced linear interpolations of straight-line path between two points on a circle generate unequal spacing of points after projecting onto a circle
equal intervals unequal intervals
linearly interpolated intermediate points projection of intermediate points onto circle
Interpolation of Rotations Represented by Quaternions 99
(Eq. 3.26)
The formula for spherical linear interpolation (slerp) between unit quaternions q1 and q2 with parameter u varying from 0 to 1 is given in Equation 3.27, where q1 • q2= cosθ. Notice that this does not necessarily produce a unit quaternion, so the result must be normalized if a unit quaternion is desired.
(Eq. 3.27)
Notice that in the case u = 1 ⁄ 2, slerp(q1, q2, u) can be easily computed within a scale factor, as q1+ q2, which can then be normalized to produce a unit quaternion.
When interpolating between a series of orientations, slerping between points on the surface of a sphere has the same problem as linear interpolation between points in Euclidean space: that of first-order discontinuity (see Appendix B). Shoemake [37] suggests using cubic Bezier interpolation to smooth the interpolation between orientations. In his paper, reasonable interior control points are automat- ically calculated to define cubic segments between each pair of orientations.
To discuss this technique, assume for now that there is a need to interpolate between two-dimensional points in Euclidean space [. . . , pn–1, pn, pn+1, . . .];
these will be referred to as the interpolated points. (How to consider the calcula- tions using quaternion representations is discussed later.) Between each pair of points, two control points will be constructed. For each of the interpolation points, pn, two control points will be associated with it: the one immediately before it, bn; and the one immediately after it, an.
To calculate the control point following any particular point pn, take the vector defined by pn –1 to pn and add it to the point pn. Now take this point (marked “1”
in Figure 3.24) and find the average of it and pn+1. This becomes one of the con- Figure 3.23 The closer of the two representations of orientation is the better choice to use in interpolation
–q2 q2
q1 180 – θ
θ
θ
cos = q1•q2 = s1⋅s2+v1•v2
slerp (q2, ,q2 u) 1–u ( ) θ⋅
( )
(sin )⁄(sinθ)
( )⋅q1+(sin(u⋅θ))xu⁄(sinθ)⋅q2
=
100 3: Interpolation and Basic Techniques
Next, take the vector defined by an to pn and add it to pn to get bn (Figure 3.25). Points bn and an are the control points immediately before and after the point pn. This construction ensures first-order continuity at the junction of adja- cent curve segments (in this case, pn) because the control points on either side of the point are colinear with the control point itself.
The end conditions can be handled by a similar construction. For example, the first control point, a0, is constructed as the vector from the third interpolated point to the second point (p1 – p2) is added to the second point (Figure 3.26).
In forming a control point, the quality of the interpolated curve can be affected by adjusting the distance the control point is from its associated interpolated point while maintaining its direction from that interpolated point. For example, a new bn′ can be computed with a user-specified constant, k, as in Equation 3.28.
(Eq. 3.28)
Between any two interpolated points, a cubic Bezier curve segment is then defined by the points pn, an, bn+1, pn+1. The control point bn+1 is defined in exactly the same way that bn is defined except for using pn, pn+1, and pn+2. The cubic curve segment is then generated between pn and pn+1. See Figure 3.27.
It should be easy to see how this procedure can be converted into the 4D spher- ical world of quaternions. Instead of adding vectors, rotations are concatenated.
Averaging of orientations can easily be done by slerping to the halfway orientation, which is implemented by adding quaternions (and optionally normalizing).
Once the internal control points are computed, the De Casteljau algorithm can Figure 3.24 Finding the control point after pn
Figure 3.25 Finding the control point before pn
1 an pn
pn–1
pn+1
pn+2
pn pn–1
pn+1
pn+2 an
bn
bn′ = pn+k⋅(bn–pn)
Interpolation of Rotations Represented by Quaternions 101
construction procedure in the Euclidean case of Bezier curve interpolation is shown in Figure 3.28. See Appendix B for a more complete discussion of the procedure.
The same procedure can be used to construct the Bezier curve in four- dimensional spherical space. For example, to obtain an orientation corresponding to the u = 1/3 position along the curve, the following orientations are computed:
p1 = slerp (qn,an,1/3) p2 = slerp (an,bn+1,1/3) p3 = slerp (bn+1,qn+1,1/3) p12 = slerp (p1,p2,1/3)
Figure 3.26 Constructing the first interior control point
Figure 3.27 Construction of bn+1 and the resulting curve
Figure 3.28 De Casteljau construction of point on cubic Bezier segment at 1 ⁄ 3 (the point labeled “3”)
a0
p0
p1
p2
pn+1
pn+2 an
1 an+1 bn+1
pn–1
pn
1
1
1 2
2
3
Interpolation steps 1. 1/3 of the way between pairs
of points
2. 1/3 of the way between points of step 1
3. 1/3 of the way between points of step 2
102 3: Interpolation and Basic Techniques
where p is the quaternion representing an orientation 1 ⁄ 3 along the spherical cubic spline.
The procedure can be made especially efficient in the case of quaternion repre- sentations when calculating points at positions along the curve corresponding to u values that are powers of 1 ⁄ 2. For example, consider calculating a point at u = 1 ⁄ 4.
temp = slerp (qn,an,1/2) = qn + an p1 = slerp (qn,temp,1/2) = qn + temp temp = slerp (an,bn+1,1/2) = an + bn+1 p2 = slerp (an,temp,1/2) = an + temp temp = slerp (bn+1,qn+1,1/2) = bn+1 + qn+1 p3 = slerp (bn+1,temp,1/2) = bn+1 + temp temp = slerp (p1,p2,1/2) = p1 + p2 p12 = slerp (p1,temp,1/2) = p1 + temp temp = slerp (p2,p3,1/2) = p2 + p3 p23 = slerp (p2,temp,1/2) = p2 + temp temp = slerp (p12,p23,1/2) = p12 + p23 p = slerp (p12,temp,1/2) = p12 + temp
The procedure can be made more efficient if the points are generated in order according to binary subdivision (1/2, 1/4, 3/4, 1/8, 3/8, 5/8, 7/8, 1/16, . . .) and temporary values are saved for use in subsequent calculations.