Drawing x^2 +y^2 =r^2 without floating point calculation based on
Bresenham's line algorithm. ( raster circle drawing)
------------------------------------------------------------------------------------
void CircleDraw(int x0, int y0, int radius)
{
int f = 1 - radius;
int ddF_x = 1;
int ddF_y = -2 * radius;
int x = 0;
int y = radius;
putPixel(x0, y0 + radius);
putPixel(x0, y0 - radius);
putPixel(x0 + radius, y0);
putPixel(x0 - radius, y0);
while(x < y)
{
// ddF_x == 2 * x + 1;
// ddF_y == -2 * y;
// f == x*x + y*y - radius*radius + 2*x - y + 1;
if(f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x;
putPixel(x0 + x, y0 + y);
putPixel(x0 - x, y0 + y);
putPixel(x0 + x, y0 - y);
putPixel(x0 - x, y0 - y);
putPixel(x0 + y, y0 + x);
putPixel(x0 - y, y0 + x);
putPixel(x0 + y, y0 - x);
putPixel(x0 - y, y0 - x);
}
}
Comments