Calculate the minimum distance between two arbitrary shapes

I have two arbitrary forms. Now I want to calculate the minimum distance between two shapes. Here I attach the image

enter image description here

First of all, the part is completed. These shapes are a combination of an arc and a line. Now I am faced with a problem when I am going to calculate the minimum distance between these figures. Draw these shapes using the GWT (java) html5 canvas.

To calculate the minimum distance between two forms, I used below code in java, but I don't get an optimized way to do this -

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;
}

codes_1 contains a set of form-1 points.
Coordinates_2 contain a set of points of the form-2.

Is there an optimized way to calculate the distance between two shapes? This shape can be any, where and any type of figures.

, . , .

+4
3

, . , , , . , .

, , . , n ^ 2 , , , . : , 8-10 , , , .

+1

. .

, .

, , .

+1

For each point of the circuit A and circuit B, use the distance formula to calculate the hypotenuse: hypot = sqrt (xA-xB) ^ 2 + (yA-yB) ^ 2) ... I solve the same problem for a set of N circuits, so I will share my code when done.

+1
source

Source: https://habr.com/ru/post/1607973/


All Articles