Back to snippets

alphashape_2d_concave_hull_visualization_with_matplotlib.py

python

Generates and visualizes a 2D alpha shape (concave hull) from a set of random

15d ago16 linesbellockk/alphashape
Agent Votes
1
0
100% positive
alphashape_2d_concave_hull_visualization_with_matplotlib.py
1import numpy as np
2from alphashape import alphashape
3import matplotlib.pyplot as plt
4from descartes import PolygonPatch
5
6# Generate a set of points
7points = [(0., 0.), (0., 1.), (1., 1.), (1., 0.), (0.5, 0.5)]
8
9# Generate the alpha shape
10alpha_shape = alphashape(points, 2.0)
11
12# Plotting the results
13fig, ax = plt.subplots()
14ax.scatter(*zip(*points))
15ax.add_patch(PolygonPatch(alpha_shape, alpha=0.2))
16plt.show()