views:

120

answers:

2

I wanna find the minimum distance between two polygon. I mean, I have to find the minimum of shortest distance between each vertex of first shape with the all the vertexes of the other one. Something like Hausdorff Distance but I need minimum instead of maximum. I appreciate any suggestion. Thank you.

A: 

To start with, "shortest distance between two polygons" sounds to me like shortest distance between one point in the first polygon to another point within the second polygon. (Which may not actually be two vertices!)

Anyway, if you want to find the shortest distance between two vertices from the two polygons, then you'll have to have a look at all pairs of vertices. That is, you can't do much better than the naive n2 algorithm. (Unless you exploit some geometrical properties of the polygons like convexity, if you happen to have that.)

aioobe
I need something faster than n^2 because each one of the polygons may consist of millions of points.
Pooya
The "shortest distance" definition issue is a good point. But I don't agree with the second statement. Note that the same problem on one dimension has a trivial linear solution, despite the fact that there are ~n^2 candidates.
Eyal Schneider
Notice that it is the shortest distance between two sets.
Pooya
+5  A: 

Perhaps you should check out (PDF warning! Also note that, for some reason, the order of the pages is reversed) "Optimal Algorithms for Computing the Minimum Distance Between Two Finite Planar Sets" by Toussaint and Bhattacharya:

It is shown in this paper that the minimum distance between two finite planar sets if [sic] n points can be computed in O(n log n) worst-case running time and that this is optimal to within a constant factor. Furthermore, when the sets form a convex polygon this complexity can be reduced to O(n).

If the two polygons are crossing convex ones, perhaps you should also check out (PDF warning! Again, the order of the pages is reversed) "An Optimal Algorithm for Computing the Minimum Vertex Distance Between Two Crossing Convex Polygons" by Toussaint:

Let P = {p1, p2,..., pm} and Q = {q1, q2,..., qn} be two intersecting polygons whose vertices are specified by their cartesian coordinates in order. An optimal O(m + n) algorithm is presented for computing the minimum euclidean distance between a vertex pi in P and a vertex qj in Q.

Yaser Sulaiman
Thank you. It was helpful.
Pooya
@Pooya If it was indeed helpful, an *upvote* would be nice. If it turns out to be the most helpful answer, marking it as the *accepted answer* would be super nice.
Yaser Sulaiman
:) This is what I tried to do at the moment that I found it helpful. But my reputation is 14 and it seems that voting up requires at least 15 reputation.
Pooya
I up voted your answer.
Pooya