1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
import numpy as np
points = np.random.rand(30, 2)
Plot = True
def min_convex(points):
oignon_layers = []
while len(points) > 4:
layer = ConvexHull(points)
oignon_layers.append(layer)
points = points = np.delete(points, layer.vertices, axis=0)
if Plot == True:
plt.plot(points[:,0], points[:,1], 'o')
for layer in oignon_layers:
for simplex in layer.simplices:
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
plt.show() |
Partager