Background: This project involves mapping regions in GIS environment. I need to find then the intersection of one set of polygons with another set of polygons. I achieved this by casting my map-compatible polygons as Polygon2d (http://geom-java.sourceforge.net/api/math/geom2d/polygon/package-summary.html) and used the intersection method to find the list of vertices for the intersection polygons.
The problem: This works except when there are multiple over lapping regions between the same two polygons. The list of vertices is correct, but I need to seperate the list into each individual polygon.
The first image is what it should look like, the second is what is actually generated:
(ignore the area at the top. Thats a result of a different bug)
How do I detect and correct this situation?
Well I figured it out. I took the vertex list for the intersection polygon (blue), iterated through each pair of point, cast each line segment in the two original polygons as LineSegment2D objects and used the .contains method to check if each pair of points was in one of the line segments. If each pair of points wasn't contained within 1 line, then there is an error.
Heres the method, but keep in mind there are several proprietary classes involved.