3

所以我们有一个绘制点的函数 DrawPoint(x,y),我们必须绘制一些看起来像圆的点。如何创建这样for(i=0; i<numberOfIterations; i++)的画圈?

4

2 回答 2

5
// (cx, cy) is the center of the circle
// r is the circle radius
// the smaller the granularity, the better the circle will look
// to draw only numberOfIterations points, granularity 
// should be 2*pi / numberOfIterations

for(i=0; i<2*pi; i+=granularity)    
    DrawPoint(cx + r*sin(i), cy + r*cos(i));
于 2010-12-23T00:12:14.643 回答
4

获得体面圆的更好算法之一是 Bresenham 圆算法,也称为中点圆算法

直截了当的基本循环例程的问题在于它们往往具有别名效果并且因此看起来不正确,该算法提供了更好的近似值,但并不严格符合您的for(;;)循环要求,尽管它仍然是一个迭代循环。

于 2010-12-23T00:19:43.790 回答