Download presentation
Presentation is loading. Please wait.
Published byErik Houston Modified over 9 years ago
1
Drawing Curves Lecture 9 Mon, Sep 15, 2003
2
Drawing Functions If f(x) is a function, then thanks to the vertical-line test, for each value of x, there is at most one value of y on the graph of f(x). Therefore, we may sample points along the x-axis, compute the y-coordinates on the curve, and then draw the graph.
3
Drawing Functions For example, we may write the following. float dx = (xmax – mxin)/(numPts – 1); glBegin(GL_LINE_STRIP); for (float x = xmin; x <= xmax; x += dx); glVertex2f(x, f(x)); glEnd();
4
Drawing Functions Is it better to compute f(x) in real time? Or should we store the function values in an array? for (int i = 0; i < numPts; i++) { xcoord[i] = x; ycoord[i] = f(x); x += dx; } // Later glBegin(GL_LINE_STRIP); for (int i = 0; i < numPts; i++) glVertex2f(xcoord[i], ycoord[i]); glEnd();
5
Drawing Functions What if we want to draw many functions? If we choose to store them, how do we store them?
6
Drawing Functions What if we wanted to draw a circle? The circle fails the vertical line test. We could draw two semicircles. f 1 (x) = (r 2 – x 2 ) f 2 (x) = - (r 2 – x 2 ) Are there any problems with this? Is there a better way?
7
Curves in the Plane We generally think of curves in the plane as being described by equations in x and y Line: y = 3x + 5 Parabola: y = 2x 2 – 10 Circle: x 2 + y 2 = 100 Ellipse: x 2 + 2y 2 = 100 However, it is often easier to describe curves parametrically.
8
Parametric Curves To parameterize a curve, we define both x and y as functions of a parameter t. x = x(t) y = y(t) The parameter t may be unrestricted or it may be restricted to some range a t b.
9
Parameterizing Lines The line through two points A and B can be parameterized as x(t) = A.x + (B.x – A.x)t y(t) = A.y + (B.y – A.y)t We may write this as in the vector form P = A + (B – A)t What point do we get when t = 0? t = 1? t = ½?
10
Line Segments and Rays The line segment AB is given by x = A.x + (B.x – A.x)t y = A.y + (B.y – A.y)t 0 t 1 The ray AB is given by the same, except t 0 What about the ray BA?
11
Parameterizing Circles and Arcs The circle with center at C and radius r can be parameterized as x(t) = C.x + r cos(t) y(t) = C.y + r sin(t) 0 t 2 We get an arc if we restrict t further. For example, suppose 0 t /2.
12
Parameterizing Ovals To parameterize an oval (ellipse) with axis 2a in the x-direction and axis 2b in the y-direction, let x(t) = a cos(t) y(t) = b sin(t) 0 t 2
13
Other Curves Many interesting curves are possible. What is the shape of the following curve? x(t) = sin(t) y(t) = sin(2t) 0 t 2 How about x(t) = (t – 1) 2 y(t) = t(t – 2) 0 t 2.
14
Parametric Curves in 3D Three-dimensional curves are similar except there is also a z-coordinate given by z(t).
15
The Helix A helix of radius 1 is given by x(t) = cos(t) y(t) = sin(t) z(t) = t 0 t 2
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.