Is there a midpoint ellipse algorithm?

Is there an algorithm for constructing the midpoint of an ellipse similar to the circumference algorithm?

I searched on Google for examples, but everything I found either doesn’t work, or is intended for filled ellipses, and not for plotting. In addition, the midpoint circle algorithm on the wikipedia page refers to existence as a version of the ellipse, but has a broken link, which Google seems to be unable to help solve.

Any help would be greatly appreciated.

+5
source share
1 answer

As a result, I found the answer here:

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

Reproduced and modified to be more generally applicable below ...

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);
    }
}
+5
source

All Articles