如何在 Java 的数组中找到 2 个最近的点?
我的意见是,
int[][] tour = {{0, 0}, {4, 0}, {4, 3}, {0, 3}};
static double calcDistanceBetweenWaypoints(int[] src, int[] dest) {
assert src.length == 2;
assert dest.length == 2;
//(0,0),(0,4)
return Math.sqrt((dest[0] - src[0])*(dest[0] - src[0]) + (dest[1] - src[1])*(dest[1] - src[1]));
}
public static int[][] getClosestWaypoints(int[][] tour) {
throw new UnsupportedOperationException("Not supported yet.");
//I dont know how to do with this function.
}
我的输出是,
closest waypoints : [(4/0) -> (4/3)], distance: 3,00