fast algorithm for drawing filled circles?

前端 未结 10 1141
清歌不尽
清歌不尽 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:18

    Here's a C# rough guide (shouldn't be that hard to get the right idea for C) - this is the "raw" form without using Bresenham to eliminate repeated square-roots.

    Bitmap bmp = new Bitmap(200, 200);
    
    int r = 50; // radius
    int ox = 100, oy = 100; // origin
    
    for (int x = -r; x < r ; x++)
    {
        int height = (int)Math.Sqrt(r * r - x * x);
    
        for (int y = -height; y < height; y++)
            bmp.SetPixel(x + ox, y + oy, Color.Red);
    }
    
    bmp.Save(@"c:\users\dearwicker\Desktop\circle.bmp");
    

提交回复
热议问题