I have adapted some code from a great article I found about circle drawing by Mukund Sivaraman to execute a passed function for each point on a given circle:
template<class Function>
static void For_each_point_on_circle(Image *image, int radius, Function function)
{
int x, y;
int l;
l = (int) radius * cos (M_PI / 4);
for (x = 0; x <= l; x++)
{
y = (int) sqrt ((double) (radius * radius) - (x * x));
function(image, x, y);
function(image, x, -y);
function(image, -x, y);
function(image, -x, -y);
function(image, y, x);
function(image, y, -x);
function(image, -y, x);
function(image, -y, -x);
}
}
However, what I really need is to calculate the points around the circle in sequence, so the calls to function(image, x, y) will go from 0 to 360 degrees in sequence rather than skipping about, which is acceptable when drawing the circle.
I could calculate all the points and sort them, but I was hoping someone may know a way to do it properly, maybe using multiple loops each calculating a segment each?
Many thanks.
function(image, radius*cos(angle), radius*sin(angle))? - BlueRaja - Danny Pflughoeft