- Join us
Notes on Bézier Curves
Cubic Bézier curves, named after Pierre Bézier (1910-1999), are a form of curve found in many graphics applications, and are also found in the PostScript and PDF languages, along with TrueType and Type1 PostScript fonts. In PDF they are the only form of curve which exists. It can therefore be useful to know something about them.
Equation of a Bézier curve
The governing equation of a cubic Bézier curve is parametric in t, with x and y both being a cubic function of t, which varies from 0 to 1. There are thus eight coefficients.
This equation can be expressed graphically in terms of four control points. The control points have the following properties:
- The curve starts and ends at the first and last control point.
- The curve is enclosed by the convex quadrilateral defined by the points.
- Reversing the order of the points leaves the curve unchanged.
The behaviour of the start of the curve will now be considered. However, the final point above shows that the properties of the start apply equally to the end.
The curve starts at the first control point, and is tangent to a line joining the first and second control points. It will curve towards the third control point, and the distance of the second from the first determines a `velocity' - how sharply the curve begins to bend as it leaves the first control point.
There are several forms of curve which can be generated. If the control points form a convex quadrilateral in their natural order, then a simple curve is produced with no points of inflexion or crossings. If the order for the convex quadrilateral is 1, 2, 4, 3 then the curve will have a point of inflexion, and if it is 1, 3, 2, 4 then it may have a loop or a discontinuity in its derivative.
The above image shows on the first row the three curves obtainable by using the corners of a square as the control points. The second has a point of inflexion, the third a discontinuity in its derivative. The second row shows that these forms can be made more extreme, with a loop appearing in the final case. The first curve on the second row shows a case where one of the end points lies within the triangle formed by the other three.
Some graphics packages expect one to specify the four control points individually. Others expect the first and the last, and then provide a `handle' that one can drag out of these to specify the remaining two. In some cases, this handle is double-ended: I cannot image why.
Approximating Circles etc.
Bézier curves are often used to approximate circles and ellipses, particularly in PDF where there is no arc operator (unlike PostScript). Using four Bézier curves one can obtain a `circle' whose maximum deviation from unit radius is less the 0.03%.
It is trivial to join Bézier curves in such a fashion that the first derivative is continuous at the join. Ensuring continuity of the second derivative is merely more tedious. One can thus approximate quite accurately any smooth curve.
It is possible to construct a Bézier curve which passes through four given points. Indeed, there may be multiple solutions to this problem. However, finding them is tedious.
Other methods of constructing Bézier curves
Two other methods for generating Bézier curves deserve mention.
Firstly, one can consider the curve points to be generated by a weighted sum of the positions of the four control points. The relevant weight functions are:
w1=(1-t)**3 w2=3t.(1-t)**2 w3=3t**2.(1-t) w4=t**3and the curve is produced as t varies from 0 to 1. This form makes it clear that the control points enclose the curve.
Secondly one can consider a Bézier curve as being formed from two other such curves. The first of these has the following four control points:
a'=a b'=0.5(a+b) c'=0.5(b'+0.5(b+c)) d'=0.5(c'+0.5(0.5(b+c)+0.5(c+d)))where a,b,c,d are the orginal control points and a',b',c',d' the new control points. (The other curve is given by changing a,b,c,d to d,c,b,a in the above formulae. The point d' is common to both.) Of course d' must lie on the original curve, and the two line segements a-d' and d'-d will therefore be an approximation to the original curve. However, this process can be repeated recursively until the line segments generated are as short as desired. This form is often used for rendering the curves for it is readily implemented in fixed-point binary arithmetic.