我有一個pointlist = [P1,P2,P3 ...] 其中P1 = [X1,Y1],P2 = [X2,Y2] ...蟒蛇SciPy的德勞內繪製的點雲
我想使用scipy.spatial.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()
感謝
樣式提示:用'numpy import'替換''numpy.core.numeric import ...'' - 在Python中通常沒有嚴格的私有區域,但是從最上面的名稱空間導入是個好習慣可能。此外,你試圖繪製什麼 - 凸包,或delaunay三角測量(我的第一個答案是,在你的示例代碼之前......) –
謝謝你的提示男人!我不知道這件事! – osager