What most people suggested in this thread is "take all the points / edges of one polygon and compare them with each point / edges of the other." This will probably work fine if everything you do compares two fairly simple polygons, and if you're not too concerned about it quickly.
However, if you want a fairly simple and better method. Use, as Ben Voigt suggested, a quadratic optimization method (i.e., quadratic programming ). Basically, your polygons are your set of linear constraints, i.e. The point of your decision should lie toward the inside of each edge of your polygon (which is a limitation of inequality). And your economic function for optimization is just the Euclidean distance, i.e. Q in the standard formulation is just the identity matrix. After you select this problem, you can either use a library that solves this problem (there are many), or you can study it from a book and load your own code for it (this is a fairly simple algorithm for encoding).
If you need a real method for this, for example, if this simple test with a polygon on a polygon is the first step to more complex three-dimensional shapes (for example, solid from polygons). Then you are most likely just using a package that already does this. Here is a collection of collision detection libraries, many of which infer the depth of penetration or, equivalently, the minimum distance.
Mikael persson
source share