获得两点之间的一组坐标?

时间:2015-02-27 03:48:23

标签: java

到目前为止我所拥有的是:

public static List<String> getIds(int x, int y, int range) {

    int ax = x+range;
    int ay = y+range;

    int bx = x-range;
    int by = y-range;

    System.out.println(Point2D.distance(ax, ay, bx, by));

    // get all coordinates between those two points above.
    // and add them to the string array like "x,y";

    return null;
}

我使用Point2D.distance来确保范围是正确的,但是对于这个方法我需要获得[ax,ay][bx,by]之间的所有坐标(整数不是双精度)但我找不到任何坐标Point2D中的实用程序方法就是这样做的。

1 个答案:

答案 0 :(得分:2)

如果你想要所有积分,你需要嵌套循环,如:

for (int i = -range; i <= range; i++) {
    for (int j = -range; j <= range; j++) {
        System.out.println(String.format("(%d,%d)", x+i, y+j));
    }
}
相关问题