Quaternions (Advanced Methods in Computer Graphics) Part 5

Quaternion Linear Interpolation (LERP)

Given two unit quaternionstmpc2f9-258_thumb[2][2][2]_thumb

tmpc2f9-259_thumb[2][2][2]_thumba linear interpolation gives the quaternion

tmpc2f9-262_thumb[2][2][2]_thumb


The quaternion resulting from the above equation is converted to a unit quaternion before a transformation of the form QPQ* is applied to all points P of the object. Every unit quaternion lies on a unit sphere in the four-dimensional space spanned by the quaternion basis (1, i, j, k). The interpolated quaternions obtained from Eq. 5.61 lie on a straight line between the two points Q1 and Q2. Converting them to unit quaternions moves each interpolated quaternion to the surface of the sphere along a radial (Fig. 5.13), resulting in an uneven distribution of points and a corresponding non-uniformity in the angular velocity of the object. The speed in the middle of the interpolation path is generally much higher than the speed at the end points. The interpolated quaternions after normalization lie on an arc of a great circle between Q1 and Q2.

Continuing with our “Hammer” example in Fig. 5.8, the source and the target orientations in Table 5.1 can be converted into quaternions using Eq. 5.49. For Orientation-1, the quaternion parameters are qo(1) = 0.5, q1(1) = 0.5, q2(1) = —0.5, q3(1) = 0.5, and for Orientation-2, the values are q0(2) = 0.71, q1(2) = 0, q2(2) = 0.71, q3(2) = 0. The aß-graph and the trace of the hammer axis on the sphere are shown in Fig. 5.14.

Interpolation sequence generated using quaternion linear interpolation

Fig. 5.14 Interpolation sequence generated using quaternion linear interpolation

Subdivision of the angle between unit quaternions

Fig. 5.15 Subdivision of the angle between unit quaternions

The interpolation path obtained using quaternions is along a circular arc between the end points, which is often the most desired path. However, the non-uniform spacing of points along the arc indicates that the angular velocity is initially smaller, then increases towards the middle and slows down again towards the target.

Quaternion Spherical Linear Interpolation (SLERP)

In the previous section we saw that linear interpolation generates intermediate quaternions along a chord between Q1 and Q2 (Fig. 5.13) on the unit sphere in quaternion space. If we subdivide the angle between Q1 and Q2 uniformly, then we will get an even distribution of points on the sphere. Such a distribution will also yield a smooth rotation of the object from one orientation to another with nearly constant angular velocity. The spherical linear interpolation (SLERP) technique uses this approach to compute intermediate quaternions.

Figure 5.15 shows the geometrical constructions needed to derive the SLERP formula. In the figure, Q1 = {q0(1), g1(1), q2(1), q3(1)g and Q2 = {q0(2), q1(2), q2(2), q3(2)g are any two unit quaternions and P is another unit quaternion that is orthogonal to Q1. Treating them as vectors in quaternion space, Q2 — Q1cosß is a vector (denoted by R) from Q2′ (the projection of Q2 on Q1) to Q2, where ß is the angle between Q1 and Q2. ß is computed from the following formula:

Interpolation sequence generated using quaternion spherical linear interpolation

Fig. 5.16 Interpolation sequence generated using quaternion spherical linear interpolation

tmpc2f9-266_thumb[2][2][2][2]

Dividing R by its magnitude (sinß ), we get the unit quaternion in the direction of R. Thus

tmpc2f9-267_thumb[2][2][2][2]

Figure 5.15 shows the angle between Q1 and Q2 subdivided using an interpolation parameter t (0 < t < 1), and the interpolated unit quaternion Q generated using this subdivision. Resolving Q along the orthogonal unit directions of Q1 and P we get

tmpc2f9-268_thumb[2][2][2][2]

Substituting Eq. 5.63 and simplifying we get

tmpc2f9-269_thumb[2][2][2][2]

The above equation has a singularity when ß = 0 or ±180°. When ß = 0, both the initial and final quaternions are the same, and therefore no interpolation is necessary. When ß = ±180°, Q2 = —Q1. From Eq. 5.57 we know that this condition also corresponds to the situation where both orientations are the same.

The interpolated sequence generated by Eq. 5.65 for the “Hammer” example is shown in Fig. 5.16. Compared with the results obtained from previously discussed forms of interpolation, the smoothness of the interpolating curves as well as the uniformity in the distribution of points along them are noticeable. Spherical linear interpolation yields an optimal angle interpolation between two orientations with a constant axis of rotation. If the interpolation parameter is incremented in constant steps, spherical linear interpolation will generate a motion with constant angular velocity.

Two different interpolation paths on the quaternion sphere

Fig. 5.17 Two different interpolation paths on the quaternion sphere

When interpolating between two quaternions Q1 and Q2, we have to make sure that the interpolation is performed along the shorter arc on the great circle through the two points on the quaternion sphere. If the angle Q between Q1 and Q2 is less than 90°, we interpolate between the two quaternions (Fig. 5.17), otherwise we interpolate between Q1 and —Q2 (Fig. 5.17). In other words, if Q^ Q2 = cosQ < 0, we negate the sign of Q2. The value of cosQ is computed using the formula in Eq. 5.62.

The following sections discuss a few more applications of quaternions for representing transformations in a three-dimensional space.

Quaternion Exponentiation

We will extend the notion of exponentiation from the field of complex numbers to the domain of quaternions and also define the associated logarithmic function that is consistent with exponentiation. However, there are some subtle differences between the way in which these operations are performed on real and complex numbers and the way they are applied to quaternions.

From Eq. 5.6 we know that a unit complex number can be expressed as z = (cosi, sini). The same complex number has an alternate representation in the form z = eil. This is the well known Euler’s formula in complex numbers. We know that a unit quaternion can also be written as Q = (cosi, u sini). Similar to complex numbers, an exponential notation for unit quaternions can be introduced as follows:

tmpc2f9-271_thumb[2][2][2][2]

where u = (l, m, n) is a unit vector in three-dimensional space. For the time being, we will treat the above equation as only an alternate representation of unit quaternions. We will see the formal definition of the exponential function and how it is related to the above notation immediately after the next equation. The logarithm of the unit quaternion in Eq. 5.66 is defined as

tmpc2f9-272_thumb[2][2][2][2]

QL is a pure quaternion and its magnitude is 1. The definition of an exponential function for quaternions must be consistent with the above operation and the inverse of the log() function, such that exp(log(Q)) = Q. We thus have the following definition:

tmpc2f9-273_thumb[2][2][2][2]

The above definition leads to the following important result for any unit quaternion Q = (cos1, u sin1), and any real value t:

tmpc2f9-274_thumb[2][2][2][2]

Note that the operations Q1 and exp(Q^) both return unit quaternions. As a special case, when t = 0, we have

tmpc2f9-275_thumb[2][2][2][2]

Since quaternion multiplication is non-commutative, it immediately follows that QaQb ^ QbQa and, log(PQ) ^ log(P) + log(Q). However, the following equations are valid for all unit quaternions Q:

tmpc2f9-276_thumb[2][2][2][2]

We know that the unit quaternion Q given in Eq. 5.66 represents a rotation by an angle 21 about the unit vector u passing through the origin. From Eq. 5.69, we see that raising Q to the power of t effectively changes the angle of rotation. Thus if 0 < t < 1, then Ql gives a unit quaternion that represents a partial rotation 2t1. This result is useful for interpolating between orientations. In the next section, we will define the relative quaternion between two orientations, and then apply Eq. 5.69 to perform incremental rotations along a path from the source orientation to the target orientation. As a result, we will get another equation for the quaternion spherical linear interpolation using the exponential notation.

Relative Quaternions

In Sect. 5.6, we defined the three-dimensional orientation of an object using the parameters of rotation that transforms the object from its initial configuration to the current. This rotation can be represented by a unit quaternion. Thus two independent orientations of an object can be represented by two unit quaternions Q1 and Q2 (Fig. 5.18). In the following, we try to find the relative quaternion that performs a rotation from the first orientation to the second. This relative quaternion can be easily obtained by noting how Q1 and Q2 transform points from one frame to another.

The relative quaternion transforms an object from one orientation to another

Fig. 5.18 The relative quaternion transforms an object from one orientation to another

In Fig. 5.18, the point P1 in Orientation-1 corresponds to the point P in the initial configuration. In other words, the quaternion Q1 transforms P into P1. Similarly the quaternion Q2 transforms P into P2 in Orientation-2. Therefore,

tmpc2f9-278_thumb[2][2][2][2]

Now we seek a quaternion that transforms P1 into P2. From the first equation above, we get the inverse transformation,

tmpc2f9-279_thumb[2][2][2][2]

Substituting in the second equation, we have

tmpc2f9-280_thumb[2][2][2][2]

The above equation shows that the quaternion Q2Q1 * transforms the point P1 into P2, and therefore represents the transformation from Orientation-1 to Orientation-2. Note that Q2Q1* is a unit quaternion. Q2Q1* is called the relative quaternion between Q1 and Q2.

We now revisit the problem of interpolating between Orientation-1 and Orientation-2. Any intermediate orientation in the above example can be obtained by first applying the unit quaternion Q1 to get to Orientation-1 from the initial configuration, and then applying a partial rotation using the relative quaternion Q2Q1*. From Eq. 5.69, we know that this partial rotation can be effected by (Q2Q1*)t, where, 0 < t <1. Combining the two transformations together, we get the quaternion (Q2Q1*)tQ1. By varying t uniformly between 0 and 1, we get the quaternions that interpolate between the two orientations. What we have just obtained is another form for the quaternion spherical interpolation (SLERP) formula using the exponent function. The pseudo-code in Listing 5.1 outlines this method for rotation interpolation. When t = 0, (Q2Q1*)tQ1 becomes Q1, and when t = 1, the interpolated quaternion becomes identical to Q2.

Listing 5.1 Pseudo-code for computing SLERP equation in exponent form

Listing 5.1 Pseudo-code for computing SLERP equation in exponent form

Next post:

Previous post: