pythonscipyspatialdelaunaysimplex

How to select from the output of scipy Delaunay triangulation only simplices under certain volume (or under total line length)?


I am using the Delaunay triangulation on a set of points, trying to isolate clusters of points in a regular pattern.

My first experience with using the qhull.Delaunay object so bear with me...

from scipy.spatial import Delaunay
tri = Delaunay(array)

Currently looks like:

Delaunay output

and I've found I can print (tri.simplices) to get the list. I want to isolate only those that are in the obvious clusters, which I imagine could be done by removing those with line length or volume over a certain threshold, but I'm unsure how to manipulate the result to do this?


Solution

  • Found the answer - posting in case it is useful for others.

    The Delaunay output gives you the list of the coordinates for each point, and a nested list of which three points form each triangle.

    To access their area, first you convert this into a list of Shapely polygons, then your polygons are your oyster.

    from shapely.geometry.polygon import Polygon
    
    coord_groups = [tri.points[x] for x in tri.simplices]
    polygons = [Polygon(x) for x in coord_groups]
    
    #area of the first polygon
    polygons[0].area