具有scipy.spatial的简单2D凸包错误

时间:2018-11-28 16:28:21

标签: python

这些非常简单的代码行成功地获取了二维坐标,并相应地绘制了它们。

import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial import ConvexHull


rawdata = np.genfromtxt('test.csv', delimiter=';')
data = rawdata[1:]



hull2d=ConvexHull(data)
x = data[:, 0]
y = data[:, 1]


plt.plot(x, y, 'o')
plt.plot(x, y, 'k-')
plt.show()

似乎做错了计算凸包,看起来像this

不是应该在最外面的点周围创建一个船体(Graham Scan)吗?

1 个答案:

答案 0 :(得分:0)

您没有绘制正确的数据。根据{{​​3}},它应该看起来像:

from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt

rawdata = np.genfromtxt('test.csv', delimiter=';')
points = rawdata[1:]
hull = ConvexHull(points)
plt.plot(points[:,0], points[:,1], 'o')
for simplex in hull.simplices:
    plt.plot(points[simplex,0], points[simplex,1], 'k-')
plt.show()