Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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 */
(-R,0)
(R,0)
F ( x, y) 0 on circle F ( x, y) 0 F ( x, y) 0
inside outside
(0,-R)
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
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
(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);
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 */
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 */