如何使用 scipy.spatial.Delaunay 将所有点包含到无误差三角剖分网格中?
How to include all points into error-less triangulation mesh with scipy.spatial.Delaunay?
我正在测试 scipy.spatial.Delaunay 但无法解决两个问题:
- 网格有错误
- 网格不包含所有点
剧情代码及图片:
import numpy as np
from scipy.spatial import Delaunay,delaunay_plot_2d
import matplotlib.pyplot as plt
#input_xyz.txt contains 1000 pts in "X Y Z" (float numbers) format
points = np.loadtxt("input_xyz.txt", delimiter=" ", usecols=(0, 1))
tri = Delaunay(points)
delaunay_plot_2d(tri)
plt.plot(points[:,0], points[:,1], 'o')
plt.show()
如scipy.spatial.Delaunay所述:
"Unless you pass in the Qhull option “QJ”, Qhull does not guarantee that each input point appears as a vertex in the Delaunay triangulation."
但是如果我用QJ:
tri = Delaunay(points, qhull_options = "QJ")
我收到 Qhull 错误,如果我使用 QJn(n=一些大数字):
tri = Delaunay(points, qhull_options = "QJ200")
为了克服这个错误,生成的网格看起来很糟糕 - 到处都是三角形相互交叉。
如何使用scipy.spatial.Delaunay将所有点包含到无误差三角网格中?
问题是你的数据集没有居中。 Qhull(用于做Delaunay三角剖分)在默认选项下不会为你居中数据集,所以它运行到远离原点的舍入误差。
你可以在三角剖分前自己居中
points -= points.mean(axis=0)
tri = Delaunay(points)
我正在测试 scipy.spatial.Delaunay 但无法解决两个问题:
- 网格有错误
- 网格不包含所有点
剧情代码及图片:
import numpy as np
from scipy.spatial import Delaunay,delaunay_plot_2d
import matplotlib.pyplot as plt
#input_xyz.txt contains 1000 pts in "X Y Z" (float numbers) format
points = np.loadtxt("input_xyz.txt", delimiter=" ", usecols=(0, 1))
tri = Delaunay(points)
delaunay_plot_2d(tri)
plt.plot(points[:,0], points[:,1], 'o')
plt.show()
如scipy.spatial.Delaunay所述:
"Unless you pass in the Qhull option “QJ”, Qhull does not guarantee that each input point appears as a vertex in the Delaunay triangulation."
但是如果我用QJ:
tri = Delaunay(points, qhull_options = "QJ")
我收到 Qhull 错误,如果我使用 QJn(n=一些大数字):
tri = Delaunay(points, qhull_options = "QJ200")
为了克服这个错误,生成的网格看起来很糟糕 - 到处都是三角形相互交叉。
如何使用scipy.spatial.Delaunay将所有点包含到无误差三角网格中?
问题是你的数据集没有居中。 Qhull(用于做Delaunay三角剖分)在默认选项下不会为你居中数据集,所以它运行到远离原点的舍入误差。
你可以在三角剖分前自己居中
points -= points.mean(axis=0)
tri = Delaunay(points)