Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

SciPy Convex Hull

# A convex hull is the smallest polygon that covers all of the given points

import numpy as np
from scipy.spatialdata import ConvexHull
import mathplotlib.pyplot as plt

points = np.array([
  [2, 4],
  [3, 4],
  [3, 0],
  [2, 2],
  [4, 1],
  [1, 2],
  [5, 0],
  [3, 1],
  [1, 2],
  [0, 2]
])

hull = ConvexHull(points)
hull_points = hull.simplices

plt.scatter(points[:, 0], points [:, 1])

for simplex in hull_points:
	plt.plot(points[simplex, 0], points[simplex, 1], 'k-')

plt.show()
 
PREVIOUS NEXT
Tagged: #SciPy #Convex #Hull
ADD COMMENT
Topic
Name
9+5 =