2013-03-18 3 views
5

Gibt es einen Mittelpunkt-Ellipsen-Plot-Algorithmus ähnlich dem Mittelpunkt-Kreis-Algorithmus?Gibt es einen Mittelpunkt-Ellipsen-Algorithmus?

Ich habe auf Google nach Beispielen gesucht, aber alle, die ich gefunden habe, funktionieren entweder nicht oder sind für gefüllte Ellipsen, nicht geplottet. Außerdem bezieht sich die Wikipedia-Seite auf den Mittelpunkt-Kreisalgorithmus auf die Existenz einer Ellipsenversion, hat aber einen toten Link, den Google anscheinend nicht lösen kann.

Jede Hilfe würde dankbar geschätzt werden.

Antwort

5

fand schließlich eine Antwort hier:

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

vermehrbarer und gezwickt allgemeinen anwendbar unten zu sein ...

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); 
    } 
}