70 likes | 186 Views
Drawing Curves. Lecture 10 Wed, Sep 17, 2003. Drawing Curves Parametrically . To draw a curve that is represented parametrically, we compute the x- and y-coordinates of points on the curve for a set of values of t. Drawing Curves Parametrically.
E N D
Drawing Curves Lecture 10 Wed, Sep 17, 2003
Drawing Curves Parametrically • To draw a curve that is represented parametrically, we compute the x- and y-coordinates of points on the curve for a set of values of t.
Drawing Curves Parametrically • We regularly subdivide the range of t values into a collection of subintervals. • Over each subinterval we draw a straight line segment. • If there are too few points, then the curve looks polygonal. • If there are too many points, then the curve takes too long to draw.
Drawing Curves Parametrically • We may • Compute the (x, y) coordinates anew each time the curve is drawn, or • Compute them once and store them in arrays. • Which method is better? • Which method would the Canvas class use?
Drawing A Circle Parametrically • To draw a circle, first compute and store the coordinates of 40 points. float x[40]; float y[40]; float angle = 0.0; float dAngle = PI/20; for (int i = 0; i < 40; i++) { x[i] = cen.x + rad*cos(angle); y[i] = cen.y + rad*sin(angle); angle += dAngle; }
Drawing A Circle Parametrically • Then use OpenGL functions to draw the circle. glBegin(GL_LINE_LOOP); for (int i = 0; i < 40; i++) glVertex2f(x[i], y[i]); glEnd();
Example: Draw a Circle • DrawCircles.cpp