我从一篇很棒的文章中改编了一些代码,该文章是 Mukund Sivaraman 绘制的关于圆绘制的文章,以便为给定圆上的每个点执行传递的函数:
template<class Function>
static void For_each_point_on_circle(Image *image, int radius, Function function)
{
int x, y;
int l;
l = (int) radius * cos (M_PI / 4);
for (x = 0; x <= l; x++)
{
y = (int) sqrt ((double) (radius * radius) - (x * x));
function(image, x, y);
function(image, x, -y);
function(image, -x, y);
function(image, -x, -y);
function(image, y, x);
function(image, y, -x);
function(image, -y, x);
function(image, -y, -x);
}
}
但是,我真正需要的是按顺序计算圆周围的点,因此对 function(image, x, y) 的调用将从 0 到 360 度按顺序进行而不是跳过,这在绘制圆时是可以接受的.
我可以计算所有点并对它们进行排序,但我希望有人可能知道一种正确的方法,也许使用多个循环,每个循环计算一个段?
非常感谢。