# CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE.

## Presentation on theme: "CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE."— Presentation transcript:

CS 450: COMPUTER GRAPHICS DRAWING ELLIPSES AND OTHER CURVES SPRING 2015 DR. MICHAEL J. REALE

OVERVIEW When dealing with other kinds of curves, we can draw it in one of the following ways: Use explicit form (i.e., y = f(x)) or a parametric form (i.e., y = f(s) and x = g(s))  approximate curve with line segments Parametric form better for this  easy to get evenly-spaced points along curve path Can connect points OR use best-fitting line (linear regression or least squares approach) Use implicit form (i.e., f(x,y) = 0) and derive incremental midpoint method In this slide deck, we’ll cover: Ellipses with the midpoint method Conic sections (and broadly discuss how to draw them) Polynomials and spline curves (which we’ll cover in greater detail later)

ELLIPSES

INTRODUCTION Ellipses are basically elongated circles Formal definition: given two points F 1 (x 1, y 1 ) and F 2 (x 2, y 2 ) (the foci of the ellipses), a point (x,y) is on the ellipse if the sum of the distances from F 1 and F 2 is some constant c. Conceptually, this is like having a string whose ends are connected at F 1 and F 2, while you use a pencil to trace out the ellipse. If we expand this out, we get: The general ellipse equation: http://commons.wikimedia.org/wiki/File:Drawing_an_e llipse_via_two_tacks_a_loop_and_a_pen.jpg#mediavie wer/File:Drawing_an_ellipse_via_two_tacks_a_loop_an d_a_pen.jpg

AXIS-ALIGNED ELLIPSES Ellipses have two axes: Major axis = line passing through both foci Minor axis = line perpendicular to major axis The semimajor and semiminor axes are like radii aligned with the major and minor axes, respectively If the ellipse axes are aligned with the coordinate axes (i.e., x and y), the equation we can use is a lot simpler: …where r x = semimajor/minor axis aligned with x axis r y = semimajor/minor axis aligned with y axis

MIDPOINT ELLIPSE ALGORITHM We’re going to assume our ellipse is aligned with the x and y axes Start at (0,r y ) Increment in x and choose y UNTIL abs(slope) > 1.0 Then, decrement in y and choose x Use symmetry to copy points to other 3 quadrants

DERIVING OUR ELLIPSE FORMULA We’re going to assume our ellipses is centered at (0,0) This won’t affect which pixels we choose

OUR ELLIPSE FORMULA …which has the following properties:

GETTING THE SLOPE We’ll start by incrementing x, but we need to check the slope to make sure it isn’t <= -1.0 To get the slope, we’ll do some implicit differentiation 

TESTING THE SLOPE When the slope = -1.0 (at boundary of R1 and R2), then: When the slope < -1.0 (entering R2):

DECISION VARIABLE: REGION 1 Our decision variable for region 1 is going to be based on where (x k + 1, y k – ½) is relative to the “true” ellipse: Similar to the midpoint circle algorithm: If p1 k < 0  inside ellipse  choose y k Otherwise  outside ellipse  choose y k - 1

INCREMENTING THE DECISION VARIBLE: REGION 1 To figure out our increment, we look at the value of p1 k+1 :

INCREMENTING THE DECISION VARIBLE: REGION 1 If p1 k < 0  chose y k+1 = y k  Otherwise  chose y k+1 = y k - 1 

WHEN DO WE SWITCH TO REGION 2? We have to check when this expression becomes true: At the starting point (0,r y ), these values are: So, every iteration: Add 2r y 2 to p x If we choose (y – 1), subtract 2r x 2 from p y

INITIAL DECISION VARIABLE: REGION 1

DECISION VARIABLE: REGION 2 Decrementing in y To get next decision variable: If p2 k > 0  outside  choose x k  increment p2 k : Otherwise  inside  choose (x k + 1)  increment p2 k :

INITIAL DECISION VARIBLE: REGION 2 We’ll use the last point we had before switching to region 2: An alternative would be to start at (r x, 0) and go counterclockwise; we would then INCREMENT y and choose between x and (x – 1)

NONSTANDARD ELLIPSES We have two ways to deal with non-standard ellipses (i.e., ellipses that do not line up with the coordinate axes): 1) Adapt formulas to work over ENTIRE ellipse path 2) Get the pixels for the standard ellipse, but then transform the points (i.e., rotation matrix)

MIDPOINT ELLIPSE ALGORITHM: REGION 1 1. Input r x, r y, and ellipse center (x c, y c ); get first point for ellipse centered on origin: 2. Get initial decision variable for region 1: 3. While (2r y 2 x < 2r x 2 y) If p1 k < 0  choose (x k + 1, y k )  Otherwise  choose (x k + 1, y k – 1) 

MIDPOINT ELLIPSE ALGORITHM: REGION 2 4. Get initial value of decision variable for region 2 from last position (x 0, y 0 ) calculated in region 1: 5. While (y != 0) If p2 k > 0  choose (x k, y k – 1)  Otherwise  choose (x k + 1, y k – 1)  6. For both regions, define symmetry points: (x,y), (-x,y), (x,-y), and (-x,-y) 7. For each position (x,y), plot:

CONIC SECTIONS

A conic section (or conic) can be described with this second-degree equation: Basically, it’s any (nondegenerate) curve generated by the intersection of a plane with a top and/or bottom of a double cone “Degenerate” conics would be things like points and straight lines The values of A,B,C,D,E, and F determine what kind of curve we want If we look at (B 2 – 4AC): http://mathworld.wolfram.com/ConicSection.html

DRAWING CONIC SECTIONS Figure out where the curve is symmetrical Circles  symmetrical across 8 octants Ellipses/Hyperbolas  symmetrical across 4 quadrants Parabolas  symmetrical across vertical axis Compute decision variable formulas for areas where slope is less than 1.0 and greater than 1.0 Go through midpoint algorithm, checking when to switch because of slope

POLYNOMIALS AND SPLINE CURVES

The usual way to handle these is to break them in parametric form For example, given a third-order (cubic) polynomial: The parameter u varies from 0 to 1 (start and end of the curve) If you have a continuous curve formed with polynomial pieces  spline curve (or just splines) We’ll talk about these later Usually you would draw these by approximating them with line segments (with small increments of u)

Similar presentations