Having int i and number, if iteration and DrawPoint (x, y) function, how to draw a circle?

So, we have a DrawPoint (x, y) function that draws a point, we need to draw a certain number of points that will look like a circle. How to create one for(i=0; i<numberOfIterations; i++)for drawing a circle?

+3
source share
2 answers
// (cx, cy) is the center of the circle
// r is the circle radius
// the smaller the granularity, the better the circle will look
// to draw only numberOfIterations points, granularity 
// should be 2*pi / numberOfIterations

for(i=0; i<2*pi; i+=granularity)    
    DrawPoint(cx + r*sin(i), cy + r*cos(i));
+5
source

One of the best algorithms for getting a decent circle is the Bresenham circle algorithm, also called the Midpoint circle algorithm .

, , , for(;;), .

+4

Source: https://habr.com/ru/post/1781764/


All Articles