Transcript
Page 1: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 1

Computer Graphics (L06)EG678EX

2-D Algorithms

Page 2: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 2

Midpoint Circle Algorithm Circle function defined as:

Any point (x,y) satisfies following conditions

boundarycircletheoutsideisyxif

boundarycircletheonisyxif

boundarycircletheinsideisyxif

yxfcircle),(,0

),(,0

),(,0

),(

222),( ryxyxfcircle

Page 3: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 3

Decision parameter is the circle function; evaluated as:

222 )2

1()1(

)2

1,1(

ryx

yxfp

kk

kkcirclek

1)()()1(2

)2

1(]1)1[(

)2

1,1(

122

11

221

2

111

kkkkkkk

kk

kkcirclek

yyyyxpp

ryx

yxfp

Page 4: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 4

yk+1 = yk if pk<0

yk+1 = yk-1 otherwise

ThusPk+1 = Pk + 2xk+1+1 if pk<0

Pk+1 = Pk + 2xk+1+1-2yk+1 otherwise Also incremental evaluation of 2xk+1 and 2yk+1

2xk+1 = 2xk + 2

2yk+1 = 2yk – 2 if pk >0

At start position (x0,y0) = (0,r)2x0 = 0 and 2y0 = 2r

Page 5: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 5

Initial decision parameter

For r specified as an integer, round p0 to

P0 = 1-r

(because all increments are integers)

r

rr

rfp circle

4

5)2

1(1

)2

1,1(

22

0

Page 6: 2D Algorithms(Midpoint Circle Algorithm) Computer Graphics

Prepared By: Dipesh Gautam 6

Algorithm1. Input radius r and circle center (xc, yc) and obtain the first point on

the circumference of a circle centered on the origin as(x0,y0) = (0,r)

2. Calculate the initial value of the decision parameter asP0 = 5/4 – r

3. At each xk position, starting at k = 0, perform the following test:If pk < 0, the next point along the circle centered on (0,0) is (xk+1,yk) and

Pk+1 = pk + 2xk+1 + 1

Otherwise, the next point along the circle is (xk+1,yK-1) and Pk+1 = pk + 2xk+1 + 1 -2yk+1

Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk-24. Determine the symmetry points in the other seven octants.5. Move each calculated pixel position (x,y) onto the circular path

centered on (xc,yc) and plot the co-ordinate values:x = x + xc, y = y+yc

6. Repeat steps 3 through 5 until x ≥ y


Recommended