How can I find the alpha shape (concave hull) of a 2d point cloud? How can I find the alpha shape (concave hull) of a 2d point cloud? python python

How can I find the alpha shape (concave hull) of a 2d point cloud?


I found this in the dionysus docs which might give you the alpha shape:

complex = Filtration()fill_alpha2D_complex(points, complex)alphashape = [s for s in complex if s.data[0] <= .5]

Then I believe you need to do something like:

for simplex in alphashape:    print [v for v in simplex.vertices]


import alphashapeimport numpy as npfrom descartes import PolygonPatchimport matplotlib.pyplot as pltn = 1000points = np.random.rand(n, 2)# Define alpha parameteralpha= 20# Generate the alpha shapealpha_shape = alphashape.alphashape(points, alpha)# Initialize plotfig, ax = plt.subplots()# Plot input pointsax.scatter(*zip(*points))# Plot alpha shapeax.add_patch(PolygonPatch(alpha_shape, alpha=.5, fc='blue', ec='red'))pnts = [x for x in alpha_shape.boundary.coords]plt.scatter(*zip(*pnts),marker='s')plt.show()