Roadmap for tonight Some background. What are Bezier curves (mathematically)? Characteristics of Bezier curves. Demo. Programming Bezier curves (very high level view).
Why Bezier curves? Bezier curves are a type of parametric curve. Used for drawing and interactively editing smooth curves in computer graphics. They are a special case of NURBS (Non-Uniform Rational B-Splines). The 3D and CAD/CAM worlds have moved on to NURBS, but Bezier curves still rule 2D graphics. These types of curves are often referred to as splines. (see next slide).
Smooth curves, B.C. (Before Computers)
Originally developed in France in the late 1950 s - early 1960 s for automotive CAD/CAM by: Pierre Bezier (Renault) Paul de Casteljau (Citroen) (M. de Casteljau seems to have been somewhat camera-shy.)
Parametric Curves (2D) Instead of y = f(x) we have x = f(t) y = f(t) Vector Notation for a 2D point: P = Pxˆx + P y ŷ
If we average two points: P =0.5( P0 + P 1 ) y P 1 P P 0 x
Next consider a weighted average of two points: P = α P0 + β P 1 α + β =1 y P 1 P 0 P x
Finally let the weights be functions of a parameter, call it t. P (t) =α(t) P0 + β(t) P 1 α + β =1 As t goes from 0 to 1, P(t) traces out the straight line between P0 and P1. y P 1 P 0 x
P(t) is an example of a parametric curve. if we choose α =(1 t) β = t the straight line is a degree 1 Bezier curve. α and β are the degree 1 Bernstein polynomials: α is B 0,1 (t) β is B 1,1 (t)
The general form of the Bernstein polynomials (also called Bernstein basis functions) is: n B n i (t) = i t i (1 t) n i, i =0,...,n Bernstein polynomials are always > 0 and form a partition of unity - at any given t, the sum of all N functions of degree N is equal to 1. (Handy for a set of weight functions)
A degree N Bezier curve is a weighted average of N+1 control points, using the N+1 degree N Bernstein polynomials as weight functions: P (t) = N i=0 B i,n Pi (t) Commonest are degree 1 (straight line) and degree 3 (cubic Bezier curve). Some degree 2 (quadratic Bezier curve) in older fonts. Higher degrees seldom used - they are hard to calculate and wiggle too much. You use a chain of cubic curves instead.
Cubic Bezier Curves (the most important kind): B 0,3 (t) =(1 t) 3 B 1,3 (t) =3t(1 t) 2 B 2,3 (t) =3t 2 (1 t) B 3,3 (t) =t 3 B n,3 (t) B 0 t B 1 B 2 B 3
The result looks like this: I ve replaced P by C (for Control point). You ll see both used in the literature.
Characteristics of Bezier curves The curve goes through the endpoints C0, C3 The ends are tangent to the line segments C0-C1, C3-C2 The longer the segment, the longer the curve sticks to the segment.
The control polygon gives a rough indication of the curve shape. Quasi-local control (moving a control point affects the part of the curve near it more than other parts of the curve.) The curve lies entirely in the convex hull of the control points.
Variation diminishing - no line will have more intersections with the curve than the line has with the polyline formed by connecting the control points. Degree elevation - you can exactly represent the shape of a Bezier curve with a higher degree Bezier curve. Affine invariance. The Bezier curve created from transformed control points is the same as the transformed curve. (Otherwise computer graphics would be a nightmare.)
Subdivision - the de Casteljau algortihm Cutting a Bezier curve results in two Bezier curves.
Less desirable characteristics The parameter is in general not distance along the curve. There is no closed form expression for arc length. The offset of a Bezier curve is not a Bezier curve. Bezier curves can t represent circular arcs (or other conics) exactly. (But you can get a good enough approximation.) They are not invariant under projective transforms. (such as a 3D perspective transform.)
Drawing a Bezier Curves are drawn by flattening (tessellating) the curve into a polyline approximation such that the maximum deviation (or actually a conservative approximation to the maximum deviation) of the curve from the polyline is less than a pixel. The resulting polyline is then drawn with the usual line drawing algorithms. The polyline approximation is also used for calculating arc length and for stepping along a curve.
Chains of Beziers ( Bezier paths in Adobe/ Quartz speech) If the end points match exactly,the curve is continuous across the join. If C2,C3,C4 (in the picture) are collinear, the tangent to curve is continuous across the join. If C2,C3,C4 are collinear and C2-C3 and C3-C4 are the same length, curvature is continuous across the join.
Demo!
Programming Bezier s The PostScript Imaging model Used by PostScript, pdf, SVG and Quartz (and therefore by CoreGraphics, Cocoa and Cocoa Touch). Has a graphics context that hold settable state for things like Fill Color, Stroke Color, Stroke Width, Line Dash, Line Join, Line Cap, etc. Has a way of adding a Bezier path to the context. Has a way to tell the context to draw (stroke, fill or both) the path according to the current state held in the context.
Building a Bezier Path (conceptual) Has a notion of a current point - the active end of the path being constructed. Has four operators or functions: moveto - begins a new subpath. lineto - adds a straight line section. curveto - adds a Bezier curve. closepath - adds a line from the current point to the beginning.
Building a Bezier Path (conceptual) There may be more than one type of curveto (quadratic or cubic Bezier). There may be convenience functions that add a rectangle or ellipse to the path. A path may have more than one (disconnected) subpaths. Has a way to tell the context to draw (stroke, fill or both) the path according to the current state held in the context.
If there is time, take a quick look at the docs for: CGPathRef NSBezierPath UIBezierPath
A quick note For fitting a chain of Bezier curves to a set of points, see: An Algorithm for Automatically Fitting Digitized Curves by Philip J. Schneider in "Graphics Gems", Academic Press, 1990