Lect4 ellipse

Post on 19-May-2015

184 views 2 download

description

create

Transcript of Lect4 ellipse

CS 603 Computer GraphicsSudipta Mondal

2

Lecture outline

n Ellipse-generating algorithmn Properties of ellipsen Midpoint ellipse algorithm

3

Ellipse Generating Algorithm

n Ellipse – an elongated circle.

n A modified circle whose radius varies from amaximum value in one direction to a minimum valuein the perpendicular direction.

n A precise definition in terms ofdistance from any point on theellipse to two fixed position,called the foci of the ellipse.

n The sum of these two distancesis the same value for all pointson the ellipse.

P=(x,y)

F2

F1d2

d1

4

Ellipse Generating Algorithm

n If the distance of the two focus positions from anypoint P=(x, y) on the ellipse are labeled d1 and d2,the general equation of an ellipse:

d1 + d2 = constant

n Expressing distance d1 and d2 in terms of the focalcoordinates F1=(x1, y1) and F2=(x2, y2), we have

( ) ( ) ( ) ( ) constant22

22

21

21 =-+-+-+- yyxxyyxx

5

Ellipse Generating Algorithm

However, we will only consider ‘standard’ ellipse:

122

=÷÷ø

öççè

æ -+÷÷

ø

öççè

æ -

y

c

x

c

ryy

rxxry

xc

rx

yc

6

Symmetry

n An ellipse only has a 4-way symmetry.

(x,y)

(x,-y)

(-x,y)

(-x,-y)

rx

ry

7

Equation of an ellipse

n Consider an ellipse centered at the origin,(xc,yc)=(0,0):

Ellipse function

…and its properties:fellipse(x,y) < 0 if (x,y) is inside the ellipsefellipse(x,y) = 0 if (x,y) is on the ellipsefellipse(x,y) > 0 if (x,y) is outside the ellipse

( ) 222222, yxxye rryrxryxf -+=

122

=÷÷ø

öççè

æ+÷÷

ø

öççè

æ

yx ry

rx

8

Midpoint Ellipse Algorithm

n Ellipse is different from circle.n Similar approach with circle,

different in sampling direction.n Region 1:

n Sampling is at x directionn Choose between (xk+1, yk), or

(xk+1, yk-1)n Move out if 2r2

yx >= 2r2xy

n Region 2:n Sampling is at y directionn Choose between (xk, yk-1), or

(xk+1, yk-1)

Slope =-1

Region 1

Region 2

ry

rx

9

Decision parameters

Region 1:

p1k < 0:n midpoint is insiden choose pixel (xk+1, yk)

p1k >= 0:n midpoint is outside/onn choose pixel (xk+1, yk-1)

( )21,11 -+= kkek yxfp

Region 2:

p2k <= 0:• midpoint is inside/on• choose pixel (xk+1, yk-1)

p2k > 0:• midpoint is outside• choose pixel (xk, yk-1)

( )1,2 21 -+= kkek yxfp

10

Midpoint Ellipse Algorithm

1. Input rx, ry and ellipse center (xc, yc). Obtain the first point on anellipse centered on the origin (x0, y0) = (0, ry).

2. Calculate initial value for decision parameter in region 1 as:

3. At each xk in region 1, starting from k = 0, test p1k :

If p1k < 0, next point (xk+1, yk) and

else, next point (xk+1, yk-1) and

with 2ry2xk+1 = 2ry

2xk + 2ry2, 2rx

2yk+1 = 2rx2yk – 2rx

2

and repeat step 1 to 3 until 2ry2x ³ 2rx

2y

24122

01 xyxy rrrrp +-=

21

21 211 ykykk rxrpp ++= ++

21

21

21 2211 ykxkykk ryrxrpp +-+= +++

11

Midpoint Ellipse Algorithm4. Initial value for decision parameter in region 2:

where (x0, y0) is the last position calculate in region 1

5. At each yk in region 2, starting from k = 0, test p2k:

If p2k > 0, next point is (xk, yk-1) and

else, next point is (xk+1, yk-1) and

continue until y=0

21

21 222 xkxkk ryrpp +-= ++

( ) ( ) 2220

2221

02

0 12 yxxy rryrxrp --++=

21

21

21 2222 xkxkykk ryrxrpp +-+= +++

12

Midpoint Ellipse Algorithm

6. For both region determine symmetry points in the other 3quadrants

7. Move each calculated pixel position (x,y) onto the elliptical pathcentered on (xc,yc) and plot the coordinate values

x=x + xc, y =y + yc

13

Try this out!

Given input ellipseparameter rx=8 and ry=6,determine pixel positionsalong the ellipse path inthe first quadrant usingthe midpoint ellipsealgorithm

2ry2x = ?

2rx2y = 2rx

2ry = ?p10 = ?

k p1k (xk+1,yk+1) 2ry2 xk+1 2 rx

2yk+1

0 -332 (1,6) 72 768

1

2

3

4

5

6

k p2k (xk+1,yk+1) 2rv2 xk+1 2 rx

2yk+1

0

1

2

14

Plot pixel positions

6

5

4

3

2

1

0

0 1 2 3 4 5 6 7 8