• Tidak ada hasil yang ditemukan

Computer Graphics

N/A
N/A
Protected

Academic year: 2024

Membagikan "Computer Graphics"

Copied!
8
0
0

Teks penuh

(1)

MID POINT CIRCLE

ALGORITHM

(2)

CIRCLE ALGORITHMS

Use 8-fold symmetry and only compute pixel positions for the 45° sector.

45°

(x, y)

(y, x) (-x, y)

(y, -x)

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

(-y, x)

(-y, -x)

(3)

MIDPOINT CIRCLE ALGORITHM

y

i

y

i

-1

x

i

x

i

+1 x

i

+2

Midpoin t

x

2

+ y

2

– r

2

= 0

Assuming that we have just plotted the pixels at (x

i

, y

i

).

Which is next? (x

i

+1, y

i

) OR (x

i

+1, y

i

– 1).

- The one that is closer to the circle.

(4)

MIDPOINT CIRCLE ALGORITHM

 The decision parameter is the circle at the midpoint between the pixels y

i

and y

i

– 1.

 If p

i

< 0, the midpoint is inside the circle and the pixel y

i

is closer to the circle boundary.

 If p

i

≥ 0, the midpoint is outside the circle and the pixel y

i

- 1 is closer to the circle boundary.

1 2

2 1 2 2

2

( 1, )

( 1) ( )

i circle i i

i i

p f x y

x y r

  

    

(5)

DECISION PARAMETERS

 Decision Parameters are obtained using incremental calculations

OR

where y

i+1

is either y

i

or y

i

-1 depending on the sign of p

i

Note:

x

i+1

= x

i

+1

1 1 1 12

2 1 2 2

1 2

( 1, )

( 2) ( )

i circle i i

i i

p f x y

x y r

  

  

    

2 2 2

1

2( 1) (

1

) (

1

) 1

i i i i i i i

p

 p  x   y

 y  y

 y 

(6)

THE ALGORITHM

1. Initial values:- point (0 , r) [

x0 = 0 y0 = r

] 2. Initial decision parameter

3.

At each x

i

position, starting at i = 0

if p

i

< 0, the next point is (x

i

+ 1, y

i

) and

p

i+1

= p

i

+ 2x

i+1

+ 1

if p

i

≥ 0, the next point is (x

i

+1, y

i

-1) and

p

i+1

= p

i

+ 2x

i+1

+ 1 – 2y

i+1

where 2x

i+1

= 2x

i

+ 2 and 2y

i+1

= 2y

i

– 2

4. Determine symmetry points in the other octants 5. Repeat 3 – 4 until x becomes greater or equal to y

2 2 5

1 1

0 circle

(1,

2

) 1 (

2

)

4

p  f r     r  r   r

(7)

10    

9  

8

7

6

5

4

3

2

1

0

0 1 2 3 4 5 6 7 8 9 10

i p

i

Next 2x

i+1

2y

i+1

0 -9 (1, 10) 2 18

1 -6 (2, 10) 4 18

2 -1 (3, 10) 6 18

3 6 (4, 9) 8 18

4 -3 (5, 9) 10 16

5 8 (6, 8) 12 16

6 5 (7, 7)

r = 10

p

0

= 1 – r = -9 (if r is integer, then consider p

0

= 1 – r)

Initial point (x

0

, y

0

) = (0, 10)

2x

i+1

= 2x

i

+ 2 and 2y

i+1

= 2y

i

– 2

If (p < 0) => (x

i

+ 1, y

i

)

p

i+1

= p

i

+ 2x

i+1

+ 1 Else if (p>=0) =>

(x

i

+1, y

i

-1)

p

i+1

= p

i

+ 2x

i+1

+ 1

– 2y

i+1
(8)

MIDPOINT FUNCTION

void plotpoints(int x, int y)

{ setpixel(xcenter+x, ycenter+y);

setpixel(xcenter-x, ycenter+y);

setpixel(xcenter+x, ycenter-y);

setpixel(xcenter-x, ycenter-y);

setpixel(xcenter+y, ycenter+x);

setpixel(xcenter-y, ycenter+x);

setpixel(xcenter+y, ycenter-x);

setpixel(xcenter-y, ycenter-x);

}

void circle(int r) { int x = 0, y = r;

plotpoints(x,y);

int p = 1 – r;

while (x<y) {

x++;if (p<0) p += 2*x + 2;

else {

y--;p += 2*(x-y) + 1;

}plotpoints(x,y);

} }

Referensi

Dokumen terkait