Is there a midpoint ellipse plotting algorithm similar to the midpoint circle algorithm?
I've searched on google for examples but any I have found either don't work or are for filled ellipses, not plotted. Also, the wikipedia page on the midpoint circle algorithm refers to the existance of an ellipse version but has a dead link which google seems unable to help resolve.
Any help would be gratefully appreciated.
Is there a midpoint ellipse plotting algorithm similar to the midpoint circle algorithm?
I've searched on google for examples but any I have found either don't work or are for filled ellipses, not plotted. Also, the wikipedia page on the midpoint circle algorithm refers to the existance of an ellipse version but has a dead link which google seems unable to help resolve.
Any help would be gratefully appreciated.
Share Improve this question edited Mar 19, 2013 at 13:32 izb asked Mar 18, 2013 at 10:07 izbizb 51.9k39 gold badges118 silver badges172 bronze badges 01 Answer
Reset to default 7Eventually found an answer here:
http://geofhagopian/sablog/Slog-october/slog-10-25-05.htm
Reproduced and tweaked 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);
}
}