java - 计算两个任意形状之间的最小距离

标签 java geometry

我有两个任意形状。现在我想计算两个形状之间的最小距离。这里我附上图片

enter image description here

首先绘制部分完成。这种形状是弧和线的组合。现在,当我要计算这些形状之间的最小距离时,我遇到了问题。使用 GWT (java) html5 Canvas 绘制此形状。

为了计算两个形状之间的最小距离,我在 java 中使用了下面的代码,但我没有得到任何优化的方法来做到这一点 -

private double calculateMinimumDistance(Coordinate[] coordinates_1, Coordinate[] coordinates_2) { 
    double minDistance = 100000;
    double currentDistance = 0;

    for(int i = 0; i < coordinates_1.length; ++i) {
      for(int j = 0; j < coordinates_2.length; ++j) {
        currentDistance = coordinates_1[i].distanceTo(coordinates_2[j]);
        if(currentDistance < minDistance) {
          minDistance = currentDistance;
        }  
      } 
    }

    return minDistance;
}

coordinates_1 包含 shape-1 的点集合。
coordinates_2 包含 shape-2 的点集合。

有没有优化的方法来计算两个形状之间的距离?这种形状可以是任何地方和任何类型的形状。

Instead of calculating the minimum distance between two set of point we can do it in optimized way by calculating distance between line to line or line to arc or arc to arc. In this way we can calculate the minimum distance in optimized way.

最佳答案

将这两种形状视为平面上两组不同的点。 然后测量从第一组的每个点到第二组的每个点的距离。

为此使用嵌套的 for 循环并使用坐标几何的距离公式测量距离。

只存储最短的距离,如果你想要两点重合的距离。

关于java - 计算两个任意形状之间的最小距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32646551/

相关文章:

javascript - 如何计算两点之间的 Angular ?

java - Eclipse RCP : application specific folder

java - 登录后调用Spring认证?

java - 从jar文件中提取目录

algorithm - 如何使用用户输入的涂鸦在多边形上添加新线段

algorithm - 修剪包含闭环的套索

java - 如何从偏航角计算方向 vector ?

java - mysql如何配置tomcat 6.0

android - OpenGL ES 2.0 : Filling in a Sphere instead of it being wireframe

algorithm - 在不计算凸包本身的情况下查找点是否在一组点的凸包内