Interpolation and Basic Techniques
3.4 Path Following
3.4.2 Smoothing a Path
108 3: Interpolation and Basic Techniques
case, the camera’s position is specified by P(s), while the center of interest is speci- fied by some C(s). This requires more work by the animator but provides greater control and more flexibility. Similarly, an up vector path, U(s), might be specified so that the general up direction is defined by U(s) – P(s). This is just the general direction because a valid up vector must be perpendicular to the view vector. Thus the coordinate frame for the camera could be defined as in Equation 3.31.
(Eq. 3.31)
Instead of using a separate path for the center of interest, a simple but effective strategy is to fix it at one location for an interval of time and then move it to another location (using linear spatial interpolation and ease-in/ease-out temporal interpolation) and fix it there for a number of frames and so on. The up vector can be set as before in the default “up” direction.
Path Following 109
Pi, are averaged. This point is averaged with the original data point (Equation 3.32). Figure 3.35 shows the sample data plotted with the original data. Notice how linear interpolation tends to draw the data points in the direction of local concavities. Repeated applications of the linear interpolation to further smooth the data would continue to draw the reduced concave sections and flatten out the curve.
(Eq. 3.32)
Smoothing with Cubic Interpolation of Adjacent Values
To preserve the curvature but still smooth the data, the adjacent points on either side of a data point can be used to fit a cubic curve that is then evaluated at its midpoint. This midpoint is then averaged with the original point, as in the linear case. A cubic curve has the form shown in Equation 3.33. The two data points on either side of an original point, Pi, are used as constraints, as shown in Equation 3.34. These equations can be used to solve for the constants of the cubic curve (a, b, c, d). Equation 3.33 is then evaluated at u = 1 ⁄ 2; and the result is averaged with the original data point (see Figure 3.36). Solving for the coefficients and evaluat- ing the resulting cubic curve is a bit tedious, but the solution needs to be per- formed only once and can be put in terms of the original data points, Pi–2, Pi–1, Pi+1, Pi+2. This is shown geometrically in Figure 3.37.
(Eq. 3.33)
Figure 3.35 Sample data smoothed by linear interpolation
2.2
1.8 1.6 1.4
2
Original data
4 6 8 10
Smoothed data
Pi′ Pi Pi–1+Pi+1 ---2 +
---2 1
4---⋅Pi–1 1
2---⋅Pi 1 4---⋅Pi+1
+ +
= =
P u( ) = a u⋅ 3+b u⋅ 2+c u⋅ +d
110 3: Interpolation and Basic Techniques
(Eq. 3.34)
For the end conditions, a parabolic arc can be fit through the first, third, and fourth points, and an estimate for the second point from the start of the data set can be computed (Figure 3.38). The coefficients of the parabolic equation, P(u) = a•u2+b•u+c, can be computed from the constraints in Equation 3.35, and the equation can be used to solve for the position P1= P(1 ⁄ 3).
Figure 3.36 Smoothing data by cubic interpolation
Figure 3.37 Geometric construction of a cubic estimate for smoothing a data point Pi–2 = P( )0 = d
Pi–1 P(1 4⁄ ) a 1 64---
⋅ b 1
16---
⋅ c 1
4---
⋅ d
+ + +
= =
Pi+1 P(3 4⁄ ) a 27 64---
⋅ b 9
16---
⋅ c 3
4---
⋅ d
+ + +
= =
Pi+2 = a+b+ +c d
Pi
Pi–1
Pi+1
Pi–2
Pi+2
P(0)
P(1/4)
P(1/2)
P(3/4)
P(1)
Original data point
New estimate for Pi based on cubic curve fit through the four adjacent points Average of original data point
and estimated point
Pi–1
Pi–2
Pi+1
Pi+2 1
2 3
New estimate for Pi based on cubic curve fit through the four adjacent points
1. Average Pi–1 and Pi+1
2. Add 1/6 of the vector from Pi–2 to Pi–1
3. Add 1/6 of the vector from Pi +2 to Pi +1 to get new estimated point 4. (Not shown) Average estimated point with original data point
Path Following 111
(Eq. 3.35)
This can be rewritten in geometric form and the point can be constructed geo- metrically from the three pointsP1′ = P2 + 1 ⁄ 3 • (P0 – P3) (Figure 3.39). A similar procedure can be used to estimate the data point secondfrom the end. The very first and very last data points can be left alone if they represent hard constraints, or parabolic interpolation can be used to generate estimates for them as well, for example, P0′ = P3 + 3 • (P1 – P2). Figure 3.40 shows cubic interpolation to smooth the data with and without parabolic interpolation for the endpoints.
Smoothing with Convolution Kernels
When the data to be smoothed can be viewed as a value of a function, yi = f(xi), the data can be smoothed by convolution. Figure 3.41 shows such a function Figure 3.38 Smoothing data by parabolic interpolation
P1
P0
P2
P3 P(0)
P(1/3)
P(2/3)
P(1)
Original data point
New estimate based on parabolic curve fit through the three adjacent points Average of original data point
and estimated point
P0 P( ), 0 P2 P 2 3---
, P3 P( )1
= =
=
P0 P2
P3 2
New estimate for P1 based on parabolic curve fit through the three adjacent points
1
1. Construct vector from P3 to P0 2. Add 1/3 of the vector to P2
3. (Not shown) Average estimated point with original data point
112 3: Interpolation and Basic Techniques
where the xi are equally spaced. A smoothing kernel can be applied to the data points by viewing them as a step function (Figure 3.42). Desirable attributes of a smoothing kernel include the following: it is centered around zero, it is symmetric, it has finite support, and the area under the kernel curve equals one. Figure 3.43 shows examples of some possibilities. A new point is calculated by centering the kernel function at the position where the new point is to be computed. The new point is calculated by summing the area under the curve that results from multi- plying the kernel function, g(u), by the corresponding segment of the step func- tion, f(x), beneath it (i.e., convolution). Figure 3.44 shows a simple tent-shaped kernel applied to a step function. In the continuous case, this becomes the inte- gral, as shown in Equation 3.36, where [–s, . . . , s] is the extent of the support of the kernel function.
(Eq. 3.36)
Figure 3.40 Sample data smoothed with cubic interpolation
Figure 3.41 Sample function to be smoothed
2.2
1.8 1.6 1.4
2 4 6 8 10
2.2
1.8 1.6 1.4
2 4 6 8 10
Original data Smoothed data Cubic smoothing with parabolic
end conditions
Cubic smoothing without smoothing the endpoints
Original curve Data points of original curve
y
x 2.2
1.8 1.6 1.4
2 4 6 8 10
P x( ) f x( +u)⋅g u( )du
s
∫
=
Path Following 113
The integral can be analytically computed or approximated by discrete means.
This can be done either with or without averaging down the number of points making up the path. Additional points can also be interpolated. At the endpoints, the step function can be arbitrarily extended so as to cover the kernel function when centered over the endpoints. Often the first and last points must be fixed because of animation constraints, so care must be taken in processing these. Figure 3.44 shows how a tent kernel is used to average the step function data; Figure 3.45 Figure 3.42 Step function defined by data points of original curve
Figure 3.43 Sample smoothing kernels
y
x
20
1/20
10
1/10
20
1/10
Wide box Box
Tent Gaussian 1
a⋅ 2⋅π
--- e (x–b)
– 2⁄(2⋅a2)
⋅
114 3: Interpolation and Basic Techniques
Smoothing by B-Spline Approximation
Finally, if an approximation to the curve is sufficient, then points can be selected from the curve, and, for example, B-spline control points can be generated based on the selected points. The curve can then be regenerated using the B-spline con- trol points, which ensures that the regenerated curve is smooth even though it no longer passes through the original points.