ムクンド・シヴァラマンによる円の描画について見つけたすばらしい記事のコードを、特定の円の各点に対して渡された関数を実行するように適合させました。
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度まで順番に行われます。これは、円を描くときに許容されます。 。
すべてのポイントを計算して並べ替えることはできましたが、誰かがそれを適切に行う方法を知っていることを望んでいました。おそらく、それぞれがセグメントを計算する複数のループを使用しますか?
どうもありがとう。