# Creating a filled Bresenham's ellipse

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

## 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 on other sites

Thanks Mark! I'll have a look at this shortly, been a busy week this week! Can't wait to test out this code.

##### Share on other sites
The fun starts when you decide to draw thick ellipses.  Edited by MarkS

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 10
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632947
• Total Posts
3009364
• ### Who's Online (See full list)

There are no registered users currently online

×