# Closest distance between case and box

What would be the best way to find the closest distance between the convex hull and the aligned axis? By the closest distance I mean the pair of points on the case and the box that are closest to each other. We can assume that we know that we know that the body and the box do not intersect.

The body is defined by faces, vertices, and if necessary, we can triangulate the faces.

source to share

This paper presents an algorithm for finding the closest pair between two convex hulls. http://realtimecollisiondetection.net/pubs/SIGGRAPH04_Ericson_GJK_notes.pdf

For some time now I thought it might be one of the AABB corpuses that would make this algorithm unnecessary. Unfortunately, I have not found this to be true.

The idea behind this algorithm is that you take the Minkowski difference of two corpuses. The closest pair would be the point in this Minkowski difference closest to the origin. The cartography theorem says that in a d-dimensional space, you only need d + 1 points to represent a point in the corpus. So basically you pick d + 1 sizes of Minkowski difference sets and find their closest distance to the origin. The closest point to the origin is found using an iterative algorithm.

source to share

In the case of a case inside a box (or any other convex object):

If they do not intersect, and the closest point in the body is the top of the body, there will never be the middle of the face.

Simply repeating all vertices of the hull and calculating the distance to each side of the field will allow you to find a pair of points (top of the hull + point on the front of the box). Note that the surface of the case is parallel to one of the edges of the box and you will get more than one pair at the same distance.

Case outside the box:

The pair contains a point on the edge of the case or box and a point on the second object. Iterating over all edges of the case and window and calculating the distance to all sides of another object looks like an approach, but better should exist.

source to share