elipsedrawing

16
Ellipse Ellipse - - Generating Algorithms Generating Algorithms Ellipse Ellipse A mo dified circle whose radius varies from a maximum value in one direction (major axis) to a minimum value in the perpendicular direction (minor axis).  P=(x,y)  F 1  F 2 d 1 d 2 The sum of the two distances d 1 and d 2 , between the fixed positions F 1 and F 2 (called the foci of the ellipse) to any point P on the ellipse, is the same value, i.e. d 1 + d 2 = constant

Upload: rajaramang

Post on 07-Apr-2018

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 1/16

EllipseEllipse--Generating AlgorithmsGenerating Algorithms

•• EllipseEllipse – A modified circle whose radius varies

from a maximum value in one direction (majoraxis) to a minimum value in the perpendiculardirection (minor axis).

 P=(x,y) F 1

 F 2

d 1

d 2

• The sum of the two distances d 1 and d 2, between thefixed positions F 1 and F 2 (called the foci of the ellipse) toany point P on the ellipse, is the same value, i.e.

d 1 + d 2 = constant

Page 2: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 2/16

Ellipse PropertiesEllipse Properties

• Expressing distances d 1 and d 2 in terms of the focal

coordinates F 1 = ( x 1, x 2) and F 2 = ( x 2, y 2), we have:

• Cartesian coordinates:

• Polar coordinates:

2 2 2 2

1 1 2 2( ) ( ) ( ) ( ) constant  x x y y x x y y

r  yr  x

22

1c c

 x y

  x x y yr r 

cos

sin

c x

c y

  x x r  

  y y r  

 

 

Page 3: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 3/16

Ellipse AlgorithmsEllipse Algorithms

• Symmetry between quadrants

• Not symmetric between the two octants of aquadrant

• Thus, we must calculate pixel positions alongthe elliptical arc through one quadrant andthen we obtain positions in the remaining 3quadrants by symmetry

( x,  y)(- x,  y)

( x, - y)(- x, - y)

r  x

r  y

Page 4: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 4/16

Ellipse AlgorithmsEllipse Algorithms

• Decision parameter:

2 2 2 2 2 2

( , )ellipse y x x y f x y r x r y r r  

1

Slope = -1

r  x

r  y 2

0 if ( , ) is inside the ellipse

( , ) 0 if ( , ) is on the ellipse0 if ( , ) is outside the ellipse

ellipse

 x y

  f x y x y x y

2

2

2

2

 y

 x

r xdySlope

dx r y

Page 5: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 5/16

Ellipse AlgorithmsEllipse Algorithms

• Starting at (0, r y ) we take unit steps in the x direction until we reach the boundary between

region 1 and region 2. Then we take unit steps inthe y direction over the remainder of the curve inthe first quadrant.

• At the boundary

• therefore, we move out of region 1 whenever

1

Slope = -1

r  x

r  y 2

2 21 2 2 y xdy r x r ydx

2 22 2 y x

r x r y

Page 6: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 6/16

Midpoint Ellipse AlgorithmMidpoint Ellipse Algorithm

 x i +2 x i +1 x i 

y i -1

y i 

Midpoint

Assuming that we have just plotted the pixels at ( x i , yi ).

The next position is determined by:

12

2 2 2 2 2 212

1 ( 1, )

( 1) ( )

i ellipse i i

i x i x y

  p f x y

r x r y r r  

If  p1i < 0 the midpoint is inside the ellipse  yi is closer 

If  p1i ≥ 0 the midpoint is outside the ellipse  yi  – 1 is closer 

Page 7: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 7/16

Decision Parameter (Region 1)Decision Parameter (Region 1)

At the next position [ x i +1 + 1 = x i + 2]

OR 

where y i +1 = y i or y 

i +1

= y i 

– 1

11 1 1 2

2 2 2 2 2 211 2

1 ( 1, )

( 2) ( )

i ellipse i i

  y i x i x y

  p f x y

r x r y r r  

2 2 2 2 2 21 1

1 1 2 21 1 2 ( 1) ( ) ( )i i y i y x i i  p p r x r r y y

Page 8: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 8/16

Decision Parameter (Region 1)Decision Parameter (Region 1)

Decision parameters are incremented

by:

Use only addition and subtraction byobtaining

At initial position (0, r y )

2 2

1

2 2 2

1 1

2 if 1 02 2 if 1 0

  y i y i

  y i y x i i

r x r pincrement r x r r y p

2 22 and 2 y xr x r y

2

2 2

2 2 2 2 21 10 2 2

2 2 214

2 0

2 2

1 (1, ) ( )

 

 y

  x x y

ellipse y y x y x y

  y x y x

r x

r y r r  

  p f r r r r r r  

r r r r  

Page 9: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 9/16

Region 2Region 2

Over region 2, step in the negative y direction andmidpoint is taken between horizontal pixels at eachstep.

 x i +2 x i +1 x i 

y i 

-1

y i 

Midpoint

Decision parameter:

12

2 2 2 2 2 212

2 ( , 1)

( ) ( 1)

i ellipse i i

i x i x y

  p f x y

r x r y r r  

If  p2i> 0 the midpoint is outside the ellipse  x 

i is closer 

If  p2i ≤ 0 the midpoint is inside the ellipse  x i + 1 is closer 

Page 10: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 10/16

Decision Parameter (RegionDecision Parameter (Region2)2)

At the next position [y i +1 – 1 = y i – 2]

OR 

where x i +1 = x i or x 

i +1

= x i 

+ 1

11 1 12

2 2 2 2 2 211 2

2 ( , 1)

( ) ( 2)

i ellipse i i

  y i x i x y

  p f x y

r x r y r r  

2 2 2 2 21 1

1 1 2 22 2 2 ( 1) ( ) ( )i i x i x y i i  p p r y r r x x

Page 11: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 11/16

Decision Parameter (Region 2)Decision Parameter (Region 2)

Decision parameters are incrementedby:

At initial position ( x 0, y 0) is taken at thelast position selected in region 1

2 2

1

2 2 2

1 1

2 if 2 0

2 2 if 2 0

  x i x i

  y i x i x i

r y r pincrement 

r x r y r p

10 0 02

2 2 2 2 2 210 02

2 ( , 1)

( ) ( 1)

ellipse

  x x y

  p f x y

r x r y r r  

Page 12: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 12/16

Midpoint Ellipse AlgorithmMidpoint Ellipse Algorithm

1. Input r  x , r y , and ellipse center ( x c , y c ), and obtain thefirst point on an ellipse centered on the origin as

( x 0, y 0) = (0, r y )

2. Calculate the initial parameter in region 1 as

3. At each x i position, starting at i = 0, if  p1i < 0, thenext point along the ellipse centered on (0, 0) is ( x i +1, y i ) and

otherwise, the next point is ( x i + 1, y i – 1) and

and continue until

2 2 210 4

1   y x y x  p r r r r  

2 2

1 11 1 2i i y i y  p p r x r  

2 2 2

1 1 11 1 2 2i i y i x i y  p p r x r y r  

2 2

2 2 y xr x r y

Page 13: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 13/16

Midpoint Ellipse AlgorithmMidpoint Ellipse Algorithm4. ( x 0, y 0) is the last position calculated in region 1. Calculate

the initial parameter in region 2 as

5. At each y i position, starting at i = 0, if  p2i > 0, the nextpoint along the ellipse centered on (0, 0) is ( x i , y i – 1) and

otherwise, the next point is ( x i + 1, y i – 1) and

Use the same incremental calculations as in region 1.Continue until y = 0.

6. For both regions determine symmetry points in the other

three quadrants.7. Move each calculated pixel position (x, y) onto the elliptical

path centered on ( x c , y c ) and plot the coordinate values

 x =  x +  x c  , y = y + y c 

2 2 2 2 2 210 0 022 ( ) ( 1)  x x y  p r x r y r r  

2 2

1 12 2 2i i x i x  p p r y r  

2 2 2

1 1 12 2 2 2i i y i x i x  p p r x r y r  

Page 14: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 14/16

ExampleExample

384504(7, 3)2446

512432(6, 4)2885

640360(5, 5)-108

4

640288(4, 5)2083768216(3, 6)-442

768144(2, 6)-224

1

76872(1, 6)-332

0

2r  x 2y i 

+1

2r y 2 x i 

+1

 x i +1,yi+1

 pi i 

r  x = 8 , r  y = 6

2r  y2 x = 0 (with increment 2r  y

2 = 72)

2r  x 2 y = 2r  x 2r  y (with increment -2r  x2 = -128)

Region 1Region 1

( x 0, y0) = (0, 6)

2 2 210 4

1 332  y x y x  p r r r r  

Move out of region 1 since

2r  y2 x > 2r  x 

2 y

Page 15: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 15/16

ExampleExample

8765432100

1

2

3

4

5

6

--(8, 0)7452

128576(8, 1)2331

256576(8, 2)-151

0

2r  x 2y i 

+1

2r y 2 x i 

+1

 x i +1,yi+1

 pi i 

Region 2Region 2

( x 0, y0) = (7, 3) (Last position in region 1)

10 2

2 (7 ,2) 151ellipse p f  

Stop at  y = 0

Page 16: ElipseDrawing

8/6/2019 ElipseDrawing

http://slidepdf.com/reader/full/elipsedrawing 16/16

Midpoint Ellipse FunctionMidpoint Ellipse Function void ellipse(int Rx, int Ry){

int Rx2 = Rx * Rx, Ry2 = Ry * Ry;int twoRx2 = 2 * Rx2, twoRy2 = Ry2 * Ry2;

int p, x = 0, y = Ry;int px = 0, py = twoRx2 * y;

ellisePlotPoints(xcenter, ycenter, x, y);// Region 1 p = round(Ry2 – (Rx2 * Ry) + (0.25 * Rx2));while (px < py) {

x++; px += twoRy2;

if (p < 0) p += Ry2 + px;else {y--; py -= twoRx2; p += Ry2 + px – py;

}ellisePlotPoints(xcenter, ycenter, x, y);

}// Region 2 p = round(Ry2 * (x+0.5) * (x+0.5) + Rx2 * (y-1)*(y-1) – Rx2 * Ry2;while (y > 0) {

y--; py -= twoRx2;if (p > 0) p += Rx2 – py;else {

x++; px += twoRy2; p += Rx2 – py + px;

}

ellisePlotPoints(xcenter, ycenter, x, y);}}