Bresenham Oo 2010-11-21 15:00:27 // http://en.wikipedia.org/wiki/Bresenham%27s_circle_algorithm#Optimization /****************************************************************************** * Kreisrasterisierung mit DDA erster Ordnung *****************************************************************************/ void plot4points(int cx, int cy, int x, int y) { setPixel(cx + x, cy + y); if(x != 0) setPixel(cx - x, cy + y); if(y != 0) setPixel(cx + x, cy - y); if(x != 0 && y != 0) setPixel(cx - x, cy - y); } void plot8points(int cx, int cy, int x, int y) { plot4points(cx, cy, x, y); if(x != y) plot4points(cx, cy, y, x); } void ddaCircle(float cx, float cy, float radius) { /* Im Moment wird hier ein Quadrat gezeichnet. Implementieren Sie die * Funktion stattdessen so, dass mit der DDA-Methode ein Kreis gezeichnet * wird. Verwenden Sie hier Differentiale erster Ordnung. */ /*float i; for (i = -r; i <= r; i += 1.0f) { setPixel(roundFloat(x + i), roundFloat(y - r)); setPixel(roundFloat(x + i), roundFloat(y + r)); setPixel(roundFloat(x - r), roundFloat(y + i)); setPixel(roundFloat(x + r), roundFloat(y + i)); }*/ int error = -roundFloat(radius); int x = roundFloat(radius); int y = 0; while(x >= y) { plot8points(roundFloat(cx), roundFloat(cy), x, y); error += y; ++y; error += y; if(error >= 0) { --x; error -= x; error -= x; } } }