#include #include #include int res_x = 1024; int res_y = 968; std::vector pixel; void plot(int _x, int _y) { //the center of the circle is always center of the image _x += res_x/2; _y += res_y/2; if (_x < 0 || _x >= res_x || _y < 0 || _y >= res_y) return; else pixel[res_x * _y + _x] = true; } int main() { int R = 100; int x = 0; int y = 0; int F = 0; //clear image pixel.resize(res_x*res_y,0); ///Algorithm 1 (Naiver Algorithmus für N=7R) for (int j = 0; j < 7*R; ++j) { x = int(float(R) * cos(2.0*M_PI*float(j)/float(7*R))); y = int(float(R) * sin(2.0*M_PI*float(j)/float(7*R))); plot (x,y); } ///Algorithm 2 (Verbesserter Naiver Algorithmus) int y1 = 0; //9:00 - 12:00 int y0 = 0; for (x = -R; x <= 0; ++x) { y1 = int(sqrt(R*R - x*x)); for (y = y0; y <= y1; ++y) { plot(x,y); plot(x,-y); } y0 = y1; } //3:00 - 12:00 y0 = 0; for (x = R; x > 0; --x) { y1 = int(sqrt(R*R - x*x)); for (y = y0; y <= y1; ++y) { plot(x,y); plot(x,-y); } y0 = y1; } ///Algorithm 3 (Verbesserter Bresenham-Algorithmus) x = 0; y = R; F = 1 - R; while (x < y) { ++x; if (F < 0) { F += 2*x - 1; } else { F += 2*(x - y); --y; } plot(x,y), plot(y,x); plot(-x,y), plot(y,-x); plot(x,-y), plot(-y,x); plot(-x,-y), plot(-y,-x); } return 0; }