计算两个任意形状之间的最小距离 [英] Calculate minimum distance between two arbitrary shape

查看:499
本文介绍了计算两个任意形状之间的最小距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



< img src =https://i.stack.imgur.com/QSm4z.pngalt =在这里输入图片描述>



首先所有绘制部分完成。这些形状是弧和线的组合。现在,当我要计算这些形状之间的最小距离时,我正面临着问题。为了计算两个形状之间的最小距离,我在java中使用了下面的代码,但我没有得到任何优化的方法来做到这一点 -

  private double calculateMinimumDistance(Coordinate [] coordinates_1,Coordinate [] coordinates_2){
double minDistance = 100000;
double currentDistance = 0; (int i = 0; i< coordinate_1.length; ++ i){
for(int j = 0; j< coordinates_2.length; ++ j){b

$ b currentDistance = coordinates_1 [i] .distanceTo(coordinates_2 [j]);
if(currentDistance< minDistance){
minDistance = currentDistance;
}
}
}

return minDistance;
}

coordinates_1包含shape-1的点集合。

coordinates_2包含形状点的集合-2。

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


不是计算两组点之间的最小距离
我们可以通过计算线到
线或线到弧或弧到弧之间的距离,以优化的方式进行。通过这种方式,我们可以优化的方式计算出
的最小距离。


解决方案

对于轮廓A和轮廓B中的每个点,使用距离公式计算斜边:hypot = sqrt(xA-xB)^ 2 +(yA-yB)^ 2)...我正在解决同一个问题的N轮廓,所以我会分享我的代码完成后。


I have two arbitrary shape. Now I want to calculate the minimum distance between two shapes. Here I am attaching the image

First of all draw part is completed. This Shapes are combination of Arc and line. Now I am facing problem when I am going to calculate the minimum distance between this shapes. Draw this shapes using GWT (java) html5 canvas.

For calculating minimum distance between two shape I have used below code in java but I am not getting any optimized way to do that -

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 contains the collection of points of shape-1.
coordinates_2 contains the collection of points of shape-2.

Is there any optimized way to calculate the distance between two shape? This shapes are could be any where and any type of shapes.

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 each point in contour A and contour B, use the distance formula to calculate hypotenuse: hypot=sqrt(xA-xB)^2+(yA-yB)^2)... I'm solving the same problem for an set of N contours, so I'll share my code when I'm done.

这篇关于计算两个任意形状之间的最小距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆