Sei sulla pagina 1di 10

Eight-way Symmetry of a Circle We know a circle is symmetric

about x-axis, so we need the points of only a semi-circle to plot the circle. Again the circle is symmetric about y-axis, so we need the points of only a quadrant to plot the circle. And we can see that the circle is symmetric about the line y=x and y=-x. So we need the points of only an octant to plot the circle. For a circle having centre at origin, if a point on the circle is (x, y) then the other points on the circle are shown in the figure.

If a circle is having its centre at (xc, yc), then for a point (x, y) on the circle, the other symmetric points are given by the following procedure CirclePoints. void CirclePoints(int x, int y, int value) { putpixel (xc+x, yc+y, value); putpixel (xc+y, yc+x, value); putpixel (xc-x, yc+y, value); putpixel (xc-y, yc+x, value); putpixel (xc-x, yc-y, value); putpixel (xc-y, yc-x, value); putpixel (xc+x, yc-y, value); putpixel (xc+y, yc-x, value); } /* CirclePoints */

Circle Midpoint Algorithm


draw pixels in this octant
(0,R)

(draw others using symmetry)


Implicit function for circle F ( x, y ) x 2 y 2 R 2

(-R,0)

(R,0)

F ( x, y) 0 on circle F ( x, y) 0 F ( x, y) 0

inside outside

(0,-R)

Choosing the Next Pixel


decision variable d
(x, y) (x+1, y) E M SE (x+1, y-1)

d F (M ) F ( x 1, y 1 / 2) F ( x 1, y 1 / 2) 0 F ( x 1, y 1 / 2) 0

choose E choose SE

Change of d when E is chosen


(x, y) (x+1, y) E Mold (x+2, y)

Mnew (x+2, y-1)


2 2

SE (x+1, y-1)
2

d new ( x 2) ( y 1 / 2) R d old ( x 1) ( y 1 / 2) R
2 2 2

d d new d old 2 x 3

Change of d when SE is chosen


d new ( x 2) ( y 3 / 2) R
2 2 2

(x, y)

(x+1, y) E Mold SE

d old ( x 1) ( y 1 / 2) R
2 2

d d new d old 2 x 2 y 5

Mnew
(x+1, y-2) (x+2, y-2)

Initial value of d
(0,R) (1,R) M0 (1,R-1)

d0 F (M 0 ) d 0 F (1, R 1 / 2) d 0 (1) ( R 1 / 2) R
2 2 2

d0 5 / 4 R

Void MidpointCircle(int R, int value) /* Assume center of the circle is at(xc, yc) */ { int x = 0; int y = R; doubel d = 5/4 R; /* real */ CirclePoints(x,y,value);

Midpoint Circle Algo

while (y > x) { if (d < 0) /* E chosen */ d += 2*x + 3; else { /* SE chosen */ d += 2*(x-y) + 5; y--; } x++; CirclePoints(x,y,value); } /* while */ } /* MidpointCircle */

New Decision Variable


Our circle algorithm requires arithmetic with real numbers. Lets create a new decision variable h
h=d-1/4

Substitute h+1/4 for d in the code. Note h < -1/4 can be replaced with h < 0 since h will always have an integer value.

Void MidpointCircle(int R, int value) /* Assume center of the circle is at(xc, yc) */ { int x = 0; int y = R; h = 1 R; CirclePoints(x,y,value); while (y > x) { if (h < 0) /* E chosen */ h += 2*x + 3; else { /* SE chosen */ h += 2*(x-y) + 5; y--; } x++; CirclePoints(x,y,value); } /* while */ } /* MidpointCircle */

New Circle Algorithm

Potrebbero piacerti anche