Cubic Bezier Curves

advertisement
Cubic Bezier Curves
A cubic Bezier curve drawn over the interval 0  t  1, is produced by a relation which
has its x and y coordinates, respectively, specified by the cubic polynomial functions:
x  a(1  t )3  3ct (1  t )2  3et 2 (1  t )  gt 3
y  b(1  t ) 3  3dt (1  t ) 2  3 ft 2 (1  t )  ht 3
where the coefficients a, b, c, d, e, f, g and h are obtained from the coordinates of the four
control points (a, b), (c, d), (e, f) and (g, h). The gradient of the curve at a point, whose
coordinates are specified by a particular value of t, can be determined using the chain rule
for differentiation, by the relationship:
dy
dx
dy
dy dy dx
 0.
 dt
and so
provided

dx
dt
dx
dt dx dt
dt
The shape of the Bezier curve produced depends on the selection of coordinate values for
the control points.
The file "Cubic Bezier curve.xls" contains two sheets. The worksheet "Curve" takes as its
input the coordinates of four control points and produces the coordinates of points along
the curve, the slope of the curve at these points and finally plots the corresponding Bezier
curve and the control points joined by straight lines. The worksheet "Formulae" shows
the formulae used in each of the cells.
Entering the coordinates of the control points
The worksheet "Curve" takes as its input the coordinates of four control points, (a, b), (c,
d), (e, f) and (g, h). These are to be entered into cells B5:C8, as follows:
5
6
7
8
B
a
c
e
g
C
b
d
f
h
The rest of this worksheet has been locked. (It can easily be unlocked highlighting the
whole sheet and then selecting Tools, Protection, Unprotect sheet). Cell D6 gives the
slope of the line joining the control points one and two, obtained using the formula
=(C6-C5)/(B6-B5)
Cell D7 gives the slope of the line joining control points two and three, and cell D8
gives the slope of the line joining control points three and four.
Determining the x and y values of points on the curve
In cells A12:A32 values of t starting at 0 and increasing by .05 until reaching 1 have been
entered. These values of t, together with the values of the coordinates of the control
points, are substituted into the equations
x  a(1  t )3  3ct (1  t )2  3et 2 (1  t )  gt 3
y  b(1  t ) 3  3dt (1  t ) 2  3 ft 2 (1  t )  ht 3
to determine the x (cells B12:B32) and y (cells C12:C32) coordinates respectively of the
corresponding points on the cubic Bezier curve.
For example, for t = 0 (the value in cell A12), the corresponding x value (in cell B12) is
calculated by the formula
=B$5*(1-$A12)^3+3*B$6*$A12*(1-$A12)^2
+3*B$7*$A12^2*(1-$A12)+B$8*$A12^3
where cells B5 to B8 contain the x values of the control points, and the corresponding y
value (in cell C12) is calculated by the formula
=C$5*(1-$A12)^3+3*C$6*$A12*(1-$A12)^2+
3*C$7*$A12^2*(1-$A12)+C$8*$A12^3
where cells C5 to C8 contain the y values of the control points.
Determining the gradient at points on the curve
Since x  a(1  t )
respect to t , we have
3
 3ct (1  t )2  3et 2 (1  t )  gt 3
, differentiating with
dx
 3a(1  t ) 2  3c((1  t ) 2  2t (1  t ))  3e(2t (1  t )  t 2 )  3gt 2
dt
 3a(1  t ) 2  3c(1  t )(1  3t )  3et (2  3t )  3gt 2
dx
(cells D12:D32), are calculated using this formula.
dt
dx
For example, for t = 0, (the value in cell A12),
is calculated by
dt
=-3*B$5*(1-$A12)^2+3*B$6*(1-$A12)*(1-3*$A12)
+3*B$7*$A12*(2-3*$A12)+3*B$8*$A12^2
For each value of t, the values of
where cells B5 to B8 contain the x coordinates of the control points.
Since y  b(1  t )
to t , we have
3
 3dt (1  t ) 2  3 ft 2 (1  t )  ht 3 , differentiating with respect
dy
 3b(1  t ) 2  3d ((1  t ) 2  2t (1  t ))  3 f (2t (1  t )  t 2 )  3ht 2
dt
 3b(1  t ) 2  3d (1  t )(1  3t )  3 f t (2  3t )  3ht 2
dy
(cells E12:E32), are calculated using this formula.
dt
dy
dy
dy
 dt
Finally for each value of t,
is calculated by
, i.e. for each t, the value of
dx
dx
dx
dt
dy
dx
in column E is divided by the corresponding value of
from column D.
dt
dt
For each value of t, the values of
Plotting the curve
The cubic Bezier curve is plotted by a scatterplot with x-values in cells B12:B32 and y
values in cells C12:C32. The control points are also plotted by a scatterplot and are joined
by straight lines.
WARNINGS:
1. If the y values of the control points are the same, Excel 97 produces an erroneous
graph.
2. If the x values of the control points are the same, Excel 97 appears to get out of hand.
Download