Sign in to follow this  

Creating a filled Bresenham's ellipse

This topic is 811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the following code to create a Bresenham's ellipse for a voxel game. While this is complete and works great to create nice ellipse outlines, I'm struggling to figure out how I might convert this to create a filled ellipse. I was thinking of perhaps doing some sort of flood fill, but not entirely sure how I might implement it. I thought maybe I will save the map points and do a line scan across from left to right boundary and fill in between.

 

I was hoping someone might have an example of something more efficient and working. The code below is C# but more interested in how it will work and I can just convert to c#. 

void DrawEllipse(int xc, int yPos, int zc, int width, int height, VoxelInfo voxelInfo)
    {
        int a2 = width * width;
        int b2 = height * height;
        int fa2 = 4 * a2, fb2 = 4 * b2;
        int x, z, sigma;

        for (x = 0, z = height, sigma = 2 * b2 + a2 * (1 - 2 * height); b2 * x <= a2 * z; x++)
        {
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true);

            if (sigma >= 0)
            {
                sigma += fa2 * (1 - z);
                z--;
            }
            sigma += b2 * ((4 * x) + 6);
        }

        for (x = width, z = 0, sigma = 2 * a2 + b2 * (1 - 2 * width); a2 * z <= b2 * x; z++)
        {
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc + z, 9, true);
            voxelInfo.chunk.SetVoxel(xc + x, yPos, zc - z, 9, true);
            voxelInfo.chunk.SetVoxel(xc - x, yPos, zc - z, 9, true);

            if (sigma >= 0)
            {
                sigma += fb2 * (1 - x);
                x--;
            }
            sigma += a2 * ((4 * z) + 6);
        }
    }
Edited by GameObject

Share this post


Link to post
Share on other sites

This topic is 811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this