Find all integer coordinates in a given radius

前端 未结 4 973
臣服心动
臣服心动 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:57

    One way is an outer loop on x from -R to +R and an inner loop on y according to the y values of the circle at that x value (from -sqrt(r^2 - x^2) to sqrt(r^2 - x^2) if the center is at 0,0), if the center is at X,Y - simply add X or Y to all loop ranges in the same manner as you did in your example

提交回复
热议问题