Reputation: 2096
As part of more complex algorithm I need following:
How can I find the points to fill at each step so at the end of each step I have fully filled circle?
I have thinking of some circle rasterization algorithm, but this will lead to some gaps in filling.
Another way is to use some mathematical morphology operation like dilation but this seems to be computationally expensive to do.
I am generally looking for way to do this on arbitrary shape but initially circle algorithm will be enough.
Upvotes: 3
Views: 2686
Reputation: 321
Draw the circles with radii 1, 3, 5, 7, 9, ... and fill the space in between them as needed, or draw all radii 1, 2, 3, 4, 5, ... and fill the holes with proper timing proportional to distance to the center.
Both method need to draw the next radius circle early and use it in next step.
Upvotes: 0
Reputation: 2096
My current solution for circle.
Based on well known Midpoint circle algorithm
This algorithm can be applied for other types of parametric shapes (Bezier curve based for example)
For non-parametric shapes (pixel based) image convolution (dilation) with kernel with central symmetry (circle). In other words for each pixel in shape looking for neighbors in circle with small radius and setting them to be part of the set. (expensive computation)
Upvotes: 3
Reputation: 420951
Your best option is to draw and fill a slightly larger red circle, and then draw and fill the green circle. Then redo on next iteration.
To only draw the 1px border is quite tricky. Your sample image is not even quite consistent. At some places a white pixel occurs diagonally to a green pixel, and in other places that pixel is red.
Edit:
Upvotes: 3
Reputation: 6422
Another option is to draw a circle/shape with a 2pixel wide red border, and then draw a green filled circle/shape with NO border. Which should leave an approximately 1px wide edge. It depends on how whatever technique you use resolves lines to pixels.
Circle algorithms tend to be optimised for drawing circles.....See the link here
Upvotes: 2