CS 430/585 Computer Graphics I Curve Drawing Algorithms Week 4, Lecture 8 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent Computing Laboratory Department of Computer Science Drexel University http://gicl.cs.drexel.edu Outline Drawing of 2D Curves De Casteljau algorithm Subdivision algorithm Drawing parametric curves Clipping Introduction and discussion of homework #3 2 How do define a smooth curve that approximates a sequence of control points? Developed by Paul de Casteljau at Citroën in the late 950s Idea: recursively subdivide the curve and add points to refine the number of control points 3 Properties of Piecewise Linear Interpolations Given continuous curve, C piecewise linear interpolant of C, PLC and an arbitrary plane, P Then: The number of crossings of P by PLC is no greater than those of C 4 Historic Analogy: The Universe of Aristotle and Ptolemy Earth is in the center Planetary motion described as Epicycles For some planets Epicycles had to be placed on Epicycles In the similar manner we will have linear interpolation of the linear interpolating points Recall: Linear Interpolation Simple example interpolating along the line between two points (really an affine combination of points a and b) x(t) = a + (b-a)t Compiled from: http://csep0.phys.utk.edu/astr6/lect/retrograde/aristotle.html 5 6
Linear Interpolation: Example Linear Interpolation: Example 2 Constructing a parabola using three control points From analytic geometry ratio( u, v, w) = (v u)/(w u) ratio( b 0,b 0,b ) = ratio(b,b,b 2 ) = ratio(b 0,b 2 0,b ) = t 7 Constructing a Bézier curve with four control points Point b 3 0( t) is obtained by repeated linear interpolation Shown: cubic case, n=3 and t=/3 8 Basic case, with two points: Plotting a curve via repeated linear interpolation Given a sequence of control points Simple case: Mapping a parameter u to the line Generalizing to three points Interpolate and Interpolate along the resulting points 9 0 The complete solution from the algorithm for three iterations: The solution after four iterations: Final Value 2
Input:,p,p 2...p n R 3, t R Iteratively set: r =,...,n p ir (t) = ( t)p i(r ) (t) + t p (i+)(r ) (t) i = 0,...,n r and p i0 (t) = p i Then n (t) is the point with parameter value t on the Bézier curve defined by the p i s 3 : Example Results A degree 6 curve 60 points computed on the curve the black points Intermediate control points 260 the gray points 4 : Example Results Quartic curve (degree 4) 50 points computed on the curve black points All intermediate control points shown gray points De Casteljau: Arc Segment Animation 5 6 De Casteljau: Cubic Curve Animation De Casteljau: Wave Curve Animation 7 8
De Casteljau: Loop Curve Animation : Some Observations Interpolation along the curve is based only on u Drawing the curve s pixels requires iterating over u at sufficient refinement 9 20 Subdivision Bézier Curve Subdivision Common in many areas of graphics, CAD, CAGD, vision Basic idea primitives def d by control polygons set of control points is not unique more than one way to compute a curve subdivision refines representation of an object by introducing more control points Allows for local modification 2 Subdivision allows display of curves at different levels of resolution Rendering systems (OpenGL, ActiveX, etc) only display polygons or lines Subdivision generates the lines/facets that approximate the curve/surface output of subdivision sent to renderer 22 Bézier Curve Subdivision, avec de Casteljau Calculate the value of x(u) at u = /2 This creates a new control point for subdividing the curve Use the two new edges to form control polygon for two new Bezier curves 23 Bézier Curve Subdivision Observe subdivision: does not affect the shape of the curve partitions one curve into several curved pieces with (collectively) the same shape 24
Subdivision: Arc Segment Subdivision: Cubic Curve 25 26 Subdivision: Wave Curve Subdivision: Loop Curve 27 28 Bézier Curve: Degree Elevation Given a control polygon Generate additional control points Keep the curve the same In the limit, this converges to the curve defined by the original control polygon 29 Drawing Parametric Curves Two basic ways: Iterative evaluation of x(t), y(t), z(t) for incrementally spaced values of t can t easily control segment lengths and error Recursive Subdivision via de Casteljau, that stops when control points get sufficiently close to the curve i.e. when the curve is nearly a straight line Use Bresenham to draw each line segment 30
Drawing Parametric Curves via Recursive Subdivision Idea: stop subdivision when segment is flat enough to be drawn w/ straight line Curve Flatness Test: based on the convex hull if and are both less than some ε, then the curve is declared flat 3 FYI: Computing the Distance from a Point to a Line Line is defined with two points Basic idea: Project point P onto the line Find the location of the projection ( y0 y) x + ( x x0) y + ( d( P, L) = 2 ( x x ) + ( y 0 x y x y ) 0 2 0) y 0 32 Drawing Parametric Curves via Recursive Subdivision The Algorithm: DrawCurveRecSub(curve,e) If staight(curve,e) then DrawLine(curve) Else SubdivideCurve(curve,LeftCurve,RightCurve) DrawCurveRecSub(LeftCurve,e) DrawCurveRecSub(RightCurve,e) 33 Ray Curve Intersection Parametric Bezier curve p(t) = S B i (t) p i Use implicit ray (line) equation l(x,y) = ax + by + c normalized: a 2 + b 2 = Solve for intersection: l(p(t)) = 0 l(p(t)) = ax(t) + by(t) + c = a S B i (t) x i + b S B i (t) y i + c = S B i (t) a x i + S B i (t) b y i + c = S B i (t) (a x i + b y i + c) Solve: d(t) = S B i (t) d i = 0 Distance to ray: d i = a x i + b y i + c p d 0 d p 3 p 2 34 Explicitize the Curve Solve: d(t) = S B i (t) d i = 0 Define new (explicit) Bezier curve d(t) = S B i (t) d i d 0 = (0, d 0 ), d = (/3, d ), = (2/3, ), = (, ) Bezier curve d(t) intersects t-axis at same parameter t d that Bezier curve p(t) intersects ray! d 0 d 0 p d p 2 p 3 d t 35 Bezier Clipping Curve d(t) bounded by convex hull of its control points d i Find intersection of convex hull with t axis: t 0,t If curve p(t) intersects ray then intersection occurs at t in [t 0,t ] Apply de Casteljau twice to subdivide p(t) into p (t) such that = p(t 0 ) and p 3 = p(t ) Do it all over again until the curve segment shrinks to nothing If curve doesn t shrink by more than 20%, subdivide in half and redo both halves (multiple intersection) d d t d 0 t 0 t p 3 p p 3 p 2 36
Programming Assignment 4 Output B/W XPM, input PostScript like file. Create data structure to hold circles. Implement translation, rotation and scaling. Implement drawing and clipping. (you can only clip circles to /8 or the arch) Outline Clipping of 2D Curves Newtonian Method Bezier Clipping Introduction and discussion of homework #3 37 38