1
$\begingroup$

Imagine I have two convex polygons pol1 and pol2 with a shared edge. Take, as an example,

pol1 = Polygon[{{0, 0}, {Sqrt[2], 0}, {Sqrt[2], Sqrt[2]}}];
pol2 = Polygon[{{Sqrt[2], 0}, {Sqrt[2], Sqrt[2]}, {2, 0}}];

One way to find such edge is to do

RegionIntersection[pol1, pol2]
Out[]= Line[{{{1.41421, 0}, {1.41421, 1.41421}}}]

This seems to work in most cases, but it is not the ideal approach. As discussed here, Mathematica seems to sometimes have problems when dealing with floats and for some specific pairs of polygons RegionIntersection is aborted. I've found this problem with some polygons (which I can't reproduce here because they come from a vertex model simulation) but was able to fix it by instead looking at its vertex list. By simply doing

Line[Intersection[pol1[[1]], pol2[[1]]]]
Out[]= Line[{{Sqrt[2], 0}, {Sqrt[2], Sqrt[2]}}]

I get what I need. I fear, however, that for some cases this might not still be ideal and float numbers may cause some problems. What could be an alternate and efficient approach for finding the shared edge of two polygons? I tried playing around with Nearest and RegionNearest but any approach seems to be way less efficient than intersecting lists or regions. Any ideas?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.