I've seen several implementations of "polygon clipping" that allow you to 'subtract' one polygon from another, but I'm looking for something a little different.
How can I clip both polygons by subtracting an even amount from each, such that they no longer overlap?
e.g. in the picture below, the pink and red polygons are overlapping. I want to slice them both along the red line so that they're no longer overlapping.
I drew the red line by hand down the center of the intersection. It should be equidistant to the edges of the [intersection] polygon on either side. I believe this also means the left and right halves have equal area.
The polygons are not necessarily convex. They're user drawn, so they can be concave, but there won't be holes. Technically they can self-intersecting, but I should probably find another algorithm to clean or discard those ones.
I hope that's clear enough. Does this algorithm have a name? Better yet if it has an implementation in JS.
Best idea I have so far is:
- Compute the intersection of the two polygons, using one of
- Martinez-Rueda-Feito
- Sutherland–Hodgman
- Weiler–Atherton clipping algorithm
- Vatti clipping algorithm
- Compute the "center line" (haven't figured this out yet)
- Use polygon clipping again to clip off the halves from each poly