A (scalar) cubic Bezier spline B(s) is a curve that is a piecewise Bezier cubic function. A typical Bezier cubic function might be denoted by y(t).
A Bezier cubic function y(t) is a cubic function, usually thought of as restricted to the range 0 <= t <= 1. The form of the function is specified by the values of four control points, whose t coordinates are 0, 1/3, 2/3, and 1. The y values of these control points are often denoted by P0, P1, P2 and P3;
The control point P0 can be thought of as the value of y(t) at t=0. The second control point, however, is not the value of y(t) at t=1/3; instead, it may be thought of as defining the tangent line at t=0, that is:
dy/dt(0) = P1 - P0 ------ t1 - t0 dy/dt(0) = 3 * ( P1 - P0 )whence we have
P1 = P0 + 1/3 * dy/dt(0)
Similarly, the control point P3 can be thought of as the value of y(t) at t=1, while the third control point defines the tangent line at t=1:
dy/dt(1) = P3 - P2 ------ t3 - t2 dy/dt(1) = 3 * ( P3 - P2 )whence we have
P2 = P3 - 1/3 * dy/dt(1)
Because y(t) is a cubic function of t, we have a formal representation for it as:
y(t) = a * t3 + b * t2 + c * t + dFrom the control point information we have been given, we can determine that
a = P3 - 3 P2 + 3 P1 - P0 b = 3 P2 - 6 P1 + 3 P0 c = 3 P1 - 3 P0 d = P0Thus, given values for the control points, we can evaluate the Bezier function y(t).
While the control point formulation may be natural in some cases, it may be the case that we want to use a Bezier representation, but we do not see how to choose the control points. Instead, we have a set of data values, and we would be perfectly satisfied if we could use our Bezier representation to express the form of a function that exactly passes through the four specified data values (for a cubic Bezier function) or for 3*n+1 data values, for a cubic Bezier spline constructed out of a succession of Bezier functions.
It turns out that it is not difficult to take a set of four data values and determine the appropriate control point information that will guarantee that our data will be interpolated. And if we can do this for a single cubic Bezier function, the technique is simply repeated for successives sets of data, to handle the case of a cubic Bezier spline.
So, sticking with the Bezier cubic function, let us suppose that we have four values y0, y1, y2 and y3, and that we want to determine control values so that our Bezier function will pass through these data points. To force interpolation, it is only necessary to set the definition of the control point values as follows:
P0 = y0 P1 = ( -5 y0 + 18 y1 - 9 y2 + 2 y3 ) / 6 P2 = ( 2 y0 - 9 y1 + 18 y2 - 5 y3 ) / 6 P3 = y3
The above formulas were derived by evaluating the formal representation of the cubic Bezier function at t = 0, 1/3, 2/3 and 1. The four equations reduce to two "interesting" equations involving the unknowns P1 and P2. Simple Gaussian elimination then produces the solution.
The Bezier function y(t) determined by these control values will have the interpolation property we desired, namely, that:
y(0) = y0 y(1/3) = y1 y(2/3) = y2 y(1) = y3
The relationship between the control points and data points is linear, and the relationship we derived above may be written as
[ P0 ] = 1/6 * [ 6 0 0 0 ] * [y0] [ P1 ] [-5 18 -9 2 ] [y1] [ P2 ] [ 2 -9 18 -5 ] [y2] [ P3 ] [ 0 0 0 6 ] [y3]
This relationship can be inverted:
[y0] = 1/27 * [ 27 0 0 0 ] * [ P0 ] [y1] [ 8 12 6 1 ] [ P1 ] [y2] [ 1 6 12 8 ] [ P2 ] [y3] [ 0 0 0 27 ] [ P3 ]The fact that each row contains positive entries that add up to 1.0 is a partial illustration of the fact that the data values are convex combinations of the control values.
To see the difference between the usual approach and this interpolating approach, consider the case where you are approximating the function f(x) = sin(x) over the interval 0 <= x <= pi; in the usual case, we would set F(t) = f(x/pi) = sin ( pi * t ), and find
P0 = F(0) = 0.0 = 0.0 P1 = F(0) + 1/3 * dF/dt(0) = pi/3 = 1.0472 P2 = F(1) - 1/3 * dF/dt(1) = pi/3 = 1.0472 P3 = F(1) = 0.0 = 0.0Note that the value of Y1 = F(1/3) = Y2 = F(2/3) = 0.8660. In this case, some sample values of the cubic Bezier function are
T Y(T) 0.000000 0.000000 <--- Interpolation for (T0,Y0) 0.083333 0.239983 0.166667 0.436333 0.250000 0.589050 0.333333 0.698133 <--- We do NOT interpolation (T1,Y1) 0.416667 0.763583 0.500000 0.785400 <--- Here is a poor estimate of sin(pi/2)! 0.583333 0.763583 0.666667 0.698133 <--- We do NOT interpolation (T2,Y2) 0.750000 0.589050 0.833333 0.436333 0.916667 0.239983 1.000000 0.000000 <--- Interpolation for (T3,Y3)
In the interpolating case, we set
P0 = F(0) = 0.0 P1 = (-5*F(0)+18*F(1/3)- 9*F(2/3)+2*F(1))/6 = 1.2990 P2 = ( 2*F(0)- 9*F(1/3)+18*F(2/3)-5*F(1))/6 = 1.2990 P3 = F(1) = 0.0In this case, some sample values of the cubic Bezier function are
T Y(T) 0.000000 0.000000 <--- Interpolation for (T0,Y0) 0.083333 0.297687 0.166667 0.541250 0.250000 0.730687 0.333333 0.866000 <--- Interpolation for (T1,Y1) 0.416667 0.947187 0.500000 0.974250 <--- Estimate of sin(pi/2) improved! 0.583333 0.947187 0.666667 0.866000 <--- Interpolation for (T2,Y2) 0.750000 0.730687 0.833333 0.541250 0.916667 0.297688 1.00000 0.000000 <--- Interpolation for (T3,Y3)
Computer graphics users are perfectly happy with Bezier functions and splines in which the control points are used in the usual way. And there is nothing wrong with that! It's just that, sometimes, the data you have (just a string of function values) doesn't seem to "fit" the tool that's available (in this case, a Bezier function). But it's not hard to figure out a way to "massage" your data to produce the information the Bezier function wants; and if interpolation is fine with you, so much the better. (When you go for interpolation, however, you are giving up the ability to control the smoothness of the transition from one Bezier function to the next, if you are using a Bezier spline, for instance.)
You can return to the HTML web page.