I need an algorithm to intersect a (potentially non-convex) polygon with a rectangle. The rectangle will be parallel to the xy-plane, but the polygon could be any orientation.
Furthermore, I don't just need a true/false result, but also the exact points where the polygon intersects the rectangle, so that I can draw lines where the polygon overlaps the rectangle. For non-convex polygons, this could result in two or more lines of intersection.
This would be for a section-cut module that can slice a set of polygons and create a 2D "cut" where the shapes intersect the "plane," specified by a z-value.
I'm developing in Java, so if Java3(2)D has any built-in methods to help, that would be ideal.
Any help/pointers in the right direction would be greatly appreciated!
Here's a picture... I want the red line as a result of the intersection: