Using Increment method
Constructors: F (x, y) = x (2) + y (2)-R (2)
For dots f (x, Y) = 0 on a circle, for dots f (x, Y) > 0 outside the circle, for dots f (x, Y) < 0 within the circle.
M is the midpoint of P1 and P2, m= (xp+1, yp-0.5)
When F (m) is <0, M is inside the circle, the P1 point is close to the circle
When F (m) >=0, M is outside the circle, the P2 point is close to the circle
Construction discriminant d = f (M) = f (xp+1, yp-0.5)
If D < 0, then take P1, then the next pixel is d = F (xp+2, yp-0.5) = d + 2XP + 3
So the increment for 2xp+3
If D >= 0, take P2, the next pixel is d = F (xp+2, yp-1.5) = d + (2XP + 3) + ( -2yp+2)
So the increment for 2 (XP-YP) +5
D0 = F (1, R-0.5) = 1.25-r
Make E = d-0.25
Program is:
public void MidpointCircle(Graphics g, int r, int color)
{
int x, y, d;
x = 0; y = r; d = 1 -r;
g.setColor(color);
g.drawLine(x, y, x, y);
g.drawLine(y, x, y, x);
while(x < y)
{
if(d < 0)
{
d += 2 * x + 3;
x ++;
}
else
{
d += 2 * (x - y) + 5;
x ++;
y --;
}
g.setColor (color);
g.drawLine(x, y, x, y);
g.drawLine(y, x, y, x);
}
}
Compiling through