Given a two-dimensional coordinate system how can I find all points with integer coordinates in a radius from a given point? I want the points as x-coordinate and y-coordinate value.
Finding points in a square around the given point is easy and could be done like that:
for(int x = -radius + point.x; x < radius + point.x; ++x)
for(int y = -radius + point.y; y < radius + point.y; ++y)
{
points.insert(point(x, y));
}
But how can I find the points in a circle around the given point? This algorithm is performance related but not accuracy related. So it doesn't matter if a point closes to the radius than 1 is added or not. In other words, I do not need floating point accuracy.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…