Wasn't it Andrew Leach who wrote: >On Nov 10, 10:33 am, Rossko <[email protected]> wrote: >> >> See Mike's Epoly extension -http://econym.org.uk/gmap/epoly.htm >> which provides a point-in-poly test. >> Iterate through the vertices of one of your polys making the test >> against the other poly. > >Actually with this method you would need to test both, because it >would be possible to have an intersection where only one polygon has >vertices within the other (that is, if the boundaries cross such that >both boundary crossing-points are on a single boundary segment of one >of the polygons). For one of the polygons, all the vertices would lie >outside the other.
Actually, it's quite easy to find situations where two polygons intersect, but neither has any vertices inside the other. For example consider a six pointed star made from two equilateral triangles. A strategy that might work is to test all line segments from one poly against all line segments from the other poly and see if they intersect. I don't have any code that will help with that. If you need to distinguish "overlap" from "touch" then you'd also need to do something clever to detect cases where the polys cross at points that are vertices of both. And you'd need a quick vertex containment check in case one poly is entirely within the other. A much more efficient algorithm that can detect whether two convex polygons collide can be derived from the Separating Axis Theorem. Implementations (typically for games) usually don't distinguish between "touch" and "overlap", but I guess that's possible. The big downside is that it doesn't work for concave polygons. -- Mike Williams http://econym.org.uk/gmap -- You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-api?hl=.
