fast algorithm for drawing filled circles?

前端 未结 10 1165
清歌不尽
清歌不尽 2020-12-02 07:28

I am using Bresenham\'s circle algorithm for fast circle drawing. However, I also want to (at the request of the user) draw a filled circle.

Is there a fast and effi

10条回答
  •  生来不讨喜
    2020-12-02 08:22

    Just use brute force. This method iterates over a few too many pixels, but it only uses integer multiplications and additions. You completely avoid the complexity of Bresenham and the possible bottleneck of sqrt.

    for(int y=-radius; y<=radius; y++)
        for(int x=-radius; x<=radius; x++)
            if(x*x+y*y <= radius*radius)
                setpixel(origin.x+x, origin.y+y);
    

提交回复
热议问题