Originally posted by: notfred
Originally posted by: Spencer278
Originally posted by: notfred
Originally posted by: Cipherous
if there are any intersections between any pair of points (1st polygon) with another pair of points (2nd polygon), then the polygons over lap.
Not if one polygon lies entirely inside another.
there are only 2 cases to consider for polygon overlap - 2 or more segments have an intersection, OR every point in one polygon is within the other polygon. It would be sufficient to test only 1 point to check the latter case.
HOw do I determine if a point is inside a polygon?
The simplest way would just be to check if any point is inside the polygon. Which means the X and Y will be bounded by the X and Y values of the other polygon.
And how do I do that? Is there some algorithm I can use to compare points and see that one point lies inside a polygon made by the others?
Not trivially, except for special cases (triangles, rectangles, some regular n-sided polygons -- although you can break almost any polygon down into triangles). Try searching under "convex hull" algorithms for a start. If your polygons are convex, that would be all you'd need... but if they're allowed to be concave and/or self-intersecting, you have to do more sophisticated searching. This is a common problem in computer graphics (this is how z-culling works in 3D rendering, for instance), and has been researched to death, so there should be plenty of info on the web.
It's pretty easy to tell if a point is *not* inside a polygon (or at least not even close) by just finding the minimum and maximum x and y values for the polygon (that is, the minimum bounding rectangle) and seeing if the point is inside that rectangle. However, if it's in the bounding rectangle, you still need to check it more thoroughly against the actual boundaries to see if it's really inside. For two full polygons, you can find the bounding rectangles for both and see if they intersect -- if they don't, the polygons definitely don't either, and if one is completely contained inside the other, they must overlap. You can also use bounding ellipses -- these are a bit tougher to compute, but can be checked very quickly, and are much more accurate for polygons that aren't aligned on the x and y axes. Determining actual intersection requires, AFAIK, comparisons between the line segments. The math boils down to expressing the polygon as a set of lines and finding points that are on the 'interior' side of each line.
We did some of this in my graphics class back in school, but it's been a few years. If you have more specific questions, I can try to rack my brain a bit more, or dig through my textbook.