I am looking for a way to triangulate and fill the interior of the contour of a non simple (possibly self intersecting) polygon. I found some very good algorithms online to triangulate simple curves or find the convex hull of a set of points, but my need is to find the contour of a list of points that I cannot rely on it being a Jordan curve (without punching holes for every self intersection like, say, mapbox/earcut, does)
I tried a python port of mapbox's earcut (https://github.com/joshuaskelly/earcut-python) which is great but punches holes for self intersections
I couldn't try scipy.spacial
since it does not support non simple curves at all.
I'm performing my research in Python and plan to port it to JavaScript eventually but for now I am language agnostic and any algorithm would do.
import earcut
from shapely.ops import cascaded_union
from shapely.geometry import Polygon
points = [[(0,0), (100,0), (100,50), (200,100), (0,100), (20,20), (80,20), (80,80), (20,80)],[]]
data = earcut.flatten(points)
flattrangles = earcut.earcut(data['vertices'])
alltriangles = [[points[0][j] for j in tr] for tr in triangles.T.tolist()]
cascaded_union([Polygon(tr) for tr in alltriangles])
Expected one large polygon with no holes Got a polygon with two triangular holes where the self intersections are