这些非常简单的代码行成功地获取了二维坐标,并相应地绘制了它们。
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)吗?
答案 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()