下面是一个可以做你想做的事情并解决你的问题的例子:
more info hereimport numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull
points = np.random.rand(30, 2) # 30 random points in 2-D
hull = ConvexHull(points)
#xs = np.array([point[0] for point in points])
#ys = np.array([point[1] for point in points])
#xh = np.array([point[0] for point in hull.points])
#yh = np.array([point[1] for point in hull.points])
plt.plot(points[:,0], points[:,1], 'o')
for simplex in hull.simplices:
plt.plot(points[simplex, 0], points[simplex, 1], 'k-')
plt.plot(points[hull.vertices,0], points[hull.vertices,1], 'r ', lw=2)
plt.plot(points[hull.vertices[0],0], points[hull.vertices[0],1], 'ro')
plt.show()
凸壳上的点分别绘制并连接成多边形。如果你愿意,你可以进一步操纵它们。在
我认为这可能是一个很好的解决方案(简单而廉价)来实施。如果你的形状是凸的,它会很好地工作。在
如果你的形状不是都是凸的,一种可能成功的方法是根据最近的邻居对点进行排序,然后从这个排序集中绘制一个多边形。在