I want to iterate over pixels along a rasterized circular arc, given its radius, start and end angles in radians, eg:
template<typename Functor>
void arc(float startRadians, float endRadians, int radius, Functor f);
To be used like:
arc(0.f, M_PI, 10, [](int x, int y) {
std::cout << "got: " << x << " " << y << "\n";
});
There's a few catches:
- pixels have integer coordinates
radius
is also given as an integer- the rasterised arc is effectively every pixel in a sector between the arc of radius
radius
and the arc of radiusradius-1
In the picture below:
- blue pixels have been visited, red pixel is the next to be visited
- the arc is confined by the two radial lines defined by start/end angles, and the sector between the two arcs
radius
,radius-1
. - finally, if every arc with radius 0 to 100 were to be drawn, angles 0 to 2*PI, then we'd get a filled disc/circle of radius 100 and no pixel would be visited twice.
I think Bresenham's circle algorithm doesn't directly apply to this problem, because of the angle constraints and visitation order.
In stackoverflow, I believe this is the most closely related question:
Finally, OpenCV has something similar/related in spirit, but only for lines: