Search code examples
algorithmpseudocodegeometrypoint

Having an int I and number if iterations and a function DrawPoint(x,y) how to draw a circle?


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


Solution

  • // (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));