请采用 Bresenham 法绘制圆(共 30 分)。要求: (1) 给出算法的文字描述(共 15 分)。 (2) 编写函数,在给定圆心坐标和半径的情况下,计算出圆 上所有的点,并将这些点存储在数组中(共 15 分)。
void Bresenham_Circle(int xc, int yc, int r)
{
int x, y, d, d1,d2,direction,i=0; CPoint circlepoints[N];
x = 0, y = r, d = 2 * (1 - r);//初始化
while (y >= 0)
{
circlepoints[i]=CPoint(x + xc, y + yc);
circlepoints[i+1]=CPoint(x + xc, -y + yc);
circlepoints[i+2]=CPoint(-x + xc, y + yc);
circlepoints[i+3]=CPoint(-x + xc, -y + yc);i=i+4;
if (d < 0)
{
d1 = 2 * (d + y) - 1;
if (d1 < 0) direction = 1;
else direction = 2;
}
else if (d > 0)
{
d2 = 2 * (d - x) - 1;
if (d2 <= 0) direction = 2;
else direction = 3;
}
else direction = 2;
switch (direction)
{
case 1:d += 2 * x + 3; x++; break;
case 2: d += 2 * (x + 1) - 2 * (y - 1) + 2; x++, y--; break;
case 3:d += -2 * (y - 1) + 1; y--; break;
}
}
}
?
?