这是我试过的代码:
from scipy.spatial import ConvexHull
points = np.random.rand(30, 2) # 30 random points in 2-D
hull = ConvexHull(points)
import matplotlib.pyplot as plt
%matplotlib inline
corners=[]
for simplex in hull.simplices:
corners+=list(simplex)
plt.fill(points[corners, 0], points[corners, 1], 'k',alpha=0.3)
Run Code Online (Sandbox Code Playgroud)
我能得到的唯一一个情节是: matplotlib中随机点集的凸壳 你可以看到它是部分填充的.
但是我想要填充这个多边形内的所有区域.
这样做的方法是什么?
我感谢您的任何建议!
更新:答案!!!
其实我刚刚找到答案.它在SciPy的官方网站上:
我们也可以直接使用船体的顶点,这对于2-D保证是逆时针顺序
所以要做我想要的我只需要使用:
plt.fill(points[hull.vertices,0], points[hull.vertices,1], 'k', alpha=0.3)
而不是我的上层代码的最后4行.
可能这个问题/答案会帮助其他人.