Parametric Drawing of Curves and Circles in OpenGL
70 likes | 205 Vues
In this lecture, we explore how to draw curves represented parametrically by computing the x- and y-coordinates of points for a range of t values. We subdivide these ranges into intervals and connect points with straight line segments. We discuss the balance between the number of points for accuracy and performance. Additionally, we demonstrate drawing a circle parametrically by calculating 40 points and using OpenGL functions to render the shape. This method emphasizes efficiency and practical implementation for graphical applications.
Parametric Drawing of Curves and Circles in OpenGL
E N D
Presentation Transcript
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