【发布时间】:2011-09-26 03:07:39
【问题描述】:
我有一个点列表=[p1,p2,p3...] 其中 p1 = [x1,y1],p2=[x2,y2] ...
我想使用 scipy.spatial.Delaunay 对这些点云进行三角剖分,然后将其绘制出来
我该怎么做?
Delaunay 的文档真的很稀缺
到目前为止我有这个代码
from subprocess import Popen, PIPE
import os
os.environ['point_num'] = "2000"
cmd = 'rbox $point_num D2 | tail -n $point_num'
sub_process = Popen(cmd, shell=True,stdout=PIPE,stderr=PIPE)
output = sub_process.communicate()
points = [line.split() for line in output[0].split('\n') if line]
x = [p[0] for p in points if p]
y = [p[1] for p in points if p]
import matplotlib.pyplot as plt
plt.plot(x,y,'bo')
from scipy.spatial import Delaunay
dl = Delaunay(points)
convex = dl.convex_hull
from numpy.core.numeric import reshape,shape
convex = reshape(convex,(shape(convex)[0]*shape(convex)[1],1))
convex_x = [x[i] for i in convex]
convex_y = [y[i] for i in convex]
plt.plot(convex_x,convex_y,'r')
plt.show()
谢谢
【问题讨论】:
-
样式提示:将
from numpy.core.numeric import ...替换为from numpy import ...-- 在Python 中通常没有严格的私有区域,但最好从最顶层的命名空间导入。另外,您要绘制什么 - 凸包或 delaunay 三角剖分(在您的示例代码之前,我的第一个答案是......) -
感谢您的提示!我对此一无所知!
标签: python scipy triangulation delaunay