→ aht:忘了放參考文獻了... 08/14 21:45
若要用比較快的方法...
建議利用Midpoint circle algorithm...
大概寫法如下....
unsigned char f[100][100];
int main(int argc, char *argv[])
{
int i,j;
int r = 20;
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
f[i][j]=0;
}
}
circle(r,r,r);
for(i=0;i<2*r+1;i++)
{
for(j=0;j<2*r+1;j++)
{
if(f[i][j])
printf("*");
else
printf("=");
}
printf("\n");
}
system("PAUSE");
return EXIT_SUCCESS;
}
void circle(int cx, int cy, int radius)
{
int error = -radius;
int x = radius;
int y = 0;
while (x >= y)
{
plot8points(cx, cy, x, y);
error += y;
++y;
error += y;
if (error >= 0)
{
--x;
error -= x;
error -= x;
}
}
}
void plot8points(int cx, int cy, int x, int y)
{
plot4points(cx, cy, x, y);
if (x != y) plot4points(cx, cy, y, x);
}
void plot4points(int cx, int cy, int x, int y)
{
f[cx + x][ cy + y]=1;
if (x != 0) f[cx - x][ cy + y] =1;
if (y != 0) f[cx + x][ cy - y]=1;
if (x != 0 && y != 0) f[cx - x][ cy - y]=1;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.124.205.15