6

是否有类似于中点圆算法的中点椭圆绘图算法?

我已经在谷歌上搜索了示例,但我发现的任何示例要么不起作用,要么用于填充椭圆,而不是绘制。此外,关于中点圆算法的维基百科页面指的是椭圆版本的存在,但有一个死链接,谷歌似乎无法帮助解决。

任何帮助将不胜感激。

4

1 回答 1

7

终于在这里找到了答案:

http://geofhagopian.net/sablog/Slog-october/slog-10-25-05.htm

复制和调整以更普遍适用于以下......

function ellipsePlotPoints (xc,yc,  x,  y)
{
    setPixel (xc + x, yc + y);
    setPixel (xc - x, yc + y);
    setPixel (xc + x, yc - y);
    setPixel (xc - x, yc - y);
}

function ellipse(xc,yc,  a,  b)
{
    var a2 = a * a;
    var b2 = b * b;
    var twoa2 = 2 * a2;
    var twob2 = 2 * b2;
    var p;
    var x = 0;
    var y = b;
    var px = 0;
    var py = twoa2 * y;

    /* Plot the initial point in each quadrant. */
    ellipsePlotPoints (xc,yc, x, y);

    /* Region 1 */
    p = Math.round (b2 - (a2 * b) + (0.25 * a2));
    while (px < py) {
        x++;
        px += twob2;
        if (p < 0)
        p += b2 + px;
        else {
        y--;
        py -= twoa2;
        p += b2 + px - py;
        }
        ellipsePlotPoints (xc,yc, x, y);
    }

    /* Region 2 */
    p = Math.round (b2 * (x+0.5) * (x+0.5) + a2 * (y-1) * (y-1) - a2 * b2);
    while (y > 0) {
        y--;
        py -= twoa2;
        if (p > 0)
        p += a2 - py;
        else {
        x++;
        px += twob2;
        p += a2 - py + px;
        }
        ellipsePlotPoints (xc,yc, x, y);
    }
}
于 2013-03-18T16:37:47.843 回答