Find all integer coordinates in a given radius

前端 未结 4 918
臣服心动
臣服心动 2020-12-31 18:09

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-coordina

4条回答
  •  一整个雨季
    2020-12-31 18:43

    Simplest solution: take a square and filter it:

    Point point(100, 100);
    for(int x = -radius; x <= radius; ++x)
    for(int y = -radius; y <= radius; ++y)
    if(x*x + y*y <= radius* radius)   {
        points.insert(Point(x + point.x, y + point.y));
    }
    

提交回复
热议问题