I am looking for a formula/algorithm that would allow me to split an arbitrary polygon into smaller polygons using line segments.
Example 1:
All the algorithms I can find split using lines (defined by segments), as opposed to actually splitting using the segments.
This is important, because I am making many such splits "all at once", and two segments that, individually, wouldn't be able to split the polygon, now can split it.
Example 2 (Segment that will cut the polygon without splitting):
Example 3 (Two segments that, together, can split the polygon in two, but separately wouldn't)
You can imagine that the polygon is an arbitrarily shaped flat piece of wood, and the segments are straight lines we cut into it with a saw, and I would like to know what the resulting pieces of wood look like (how many and their shape)
I want to extend this behaviour to any polygon shape, and any number of "cutting" segments.
I absolutely do not mind any leftover duplicate points in the results, I can easily "clean it up" afterwards to remove consecutive duplicate points.
Best Answer
Warning : I'm not 100% sure this works. If you implement it, tell me how it went.
This is how I would do it. First, you want to have an implementation of polygons that have exterior segments and interior segments. The interior segments are not part of your final calculated polygon, but are going to be needed when you calculate new polygons. You are also going to want to think of the segments as being slowly drawn from a starting point to an end point for what I'm about to describe. When you draw a segment, compute if the starting point of the segment is inside a polygon or outside.
If you reach the end point, you are inside the polygon. Add the last segment as an interior segment to the polygon the segment is in.