Bezier Curve
Volume Number: 5
Issue Number: 1
Column Tag: C Workshop
Related Info: Quickdraw
Bezier Curve Ahead! 
By David W. Smith, Los Gatos, CA
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
David W. Smith (no known relation to the Editor) is a Sr. Software Engineer at
ACM Re search, Inc., in Los Gatos.
There comes a time in the development of some applications when arcs and wedges
just don’t cut the mustard. You want to draw a pretty curve from point A to point B,
and QuickDraw isn’t giving you any help. It seems like a good time to reach for a
computer graphics text, blow the dust off of your college math, and try to decipher
their explanation of splines. Stop. All is not lost. The Bezier curve may be just what
you need.
Bezier Curves
Bezier curves (pronounced “bez-yeah”, after their inventor, a French
mathematician) are well suited to graphics applications on the Macintosh for a number
of reasons. First, they’re simple to describe. A curve is a function of four points.
Second, the curve is efficient to calculate. From a precomputed table, the segments of
the curve can be produced using only fixed-point multiplication. No trig, no messy
quadratics, and no inSANEity. Third, and, to some, the most important, the Bezier
curve is directly supported by the PostScript curve and curveto operators, and is one
of the components of PostScript’s outlined fonts. The Bezier curve is also one of the
principle drawing elements of Adobe Illustrator™. (Recently, they’ve shown up in a
number of other places.)
Bezier curves have some interesting properties. Unlike some other classes of
curves, they can fold over on themselves. They can also be joined together to form
smooth (continuous) shapes. Figure 1 shows a few Bezier curves, including two that
are joined to form a smooth shape.
The Gruesome Details
The description of Bezier curves below is going to get a bit technical. If you’re
not comfortable with the math, you can trust that the algorithm works, and skip ahead
to the implementation. However, if you’re curious about how the curves work and how
to optimize their implementation, or just don’t trust using code that you don’t
understand, read on.
The Bezier curve is a parametric function of four points; two endpoints and two
“control” points. The curve connects the endpoints, but doesn’t necessarily touch the
control points. The general form Bezier equation, which describes each point on the
curve as a function of time, is:
where P1 and P4 are the endpoints, P2 and P3 are the control points, and the
wn’s are weighting functions, which blend the four points to produce the curve. (The
weights are applied to the h and v components of each point independently.) The single
parameter t represents time, and varies from 0 to 1. The full form of the Bezier
curve is:
We know that the curve touches each endpoint, so it isn’t too surprising that at
t=0 the first weighting function is 1 and all others are 0 (i.e., the initial point on the
curve is the first endpoint). Likewise, at t=1, the fourth weighting function is 1 and
the rest are 0. However, it’s what happens between 0 and 1 that’s really interesting.
A quick side-trip into calculus to take some first derivatives tells us that the second
weighting function is maximized (has its greatest impact on the curve) at t=1/3, and
the third weight is maximized at t=2/3. But the clever part--the bit that the
graphics books don’t bother to mention--run the curve backwards by solving the
equation for 1-t, and you find that w1(t)=w4(1-t) and w2(t)=w3(1-t). As we’ll see
below, this symmetry halves the effort needed to compute values for the weights.
Figure 1. Some Beizer Curves and Shapes
Implementing Bezier Curves