Bresenhamのアルゴリズムを変更して、必要なものを追跡するのは簡単です。アルゴリズムの関連する部分は次のとおりです。
plot(x,y);
error = error + deltaerr;
if (error >= 0.5)
{
y = y + ystep;
error = error - 1.0;
}
すべてのセルを追跡するには、別の変数が必要です。私はこれを厳密にチェックしていないことに注意してください。
plot(x,y);
olderror = error.
error = error + deltaerr;
if (error >= 0.5)
{
y = y + ystep;
error = error - 1.0;
extra = error+olderror;
if (extra > 0)
{
plot (x,y); /* not plot (x-1,y); */
}
else if (extra < 0)
{
plot (x+1,y-1); /* not plot (x+1,y); */
}
esle
{
// the line goes right through the cell corner
// either do nothing, or do both plot (x-1,y) and plot (x+1,y)
// depending on your definition of intersection
}
}
私の要件に適合しないとはどういう意味ですか?どのようにしてフィットしませんか? –
デルタパラメータにすべてのセルだけが見つかりません。ウィキペディアのサンプル画像を見てください。 –