Bézier Curves
Making smooth, but complex appearing, curves and surfaces is of great interest in computer graphics. Bézier (or Bernstein) polynomials provide a way of making complex curves that are anchored at corner points and distorted by other control points that pull it towards them as if by gravity. Cubic polynomial Bézier curves are defined by four control points. Bézier curves are a function of one real parameter, say u. As u varies, conventionally from 0.0 to 1.0, the x and y values are defined continuously. The Bézier curve starts on the first point and ends on the fourth point. The two points in the middle pull the curve towards them a little, but the curve will not, in general, intersect the two middle points. The resulting curve is very smooth.
Bézier surfaces in three dimensions are defined by sets of Bézier curves and two parameters, say u and v. If one parameter is held constant, perhaps at 0.5, and the other one varied, the curve defined is a Bézier curve and is called "isoparametric."
In the room program, I made the curves with PARM_STEP_QTY (64) steps. The parameters u and v step from 0 to 1 in 65 steps. Then a b vector is built for both u and v at each value (that's 64×64 values total; if you stored these 65 vectors for u and v you could skip recomputing them.)
b[0]=(1-u)3
b[1]=3u(1-u)2
b[2]=3(u2)(1-u)
b[3]=u3
Notice how when u=0, then b[0] will be in control, and when u=1, b[3] will be in control; those are the end-points intersected by the curve I'm building. When u is between 0 and 1, the vectors b[1] and b[2] tug the curve toward them.
-- T.E.J.
Copyright © 1999, Dr. Dobb's Journal