Algorithm 如何在python中使用库三角剖分
我想检测点集的边界。我尝试了scipy spatial的Delaunay三角剖分,但我得到了以下结果:Algorithm 如何在python中使用库三角剖分,algorithm,python-3.x,triangulation,delaunay,concave-hull,Algorithm,Python 3.x,Triangulation,Delaunay,Concave Hull,我想检测点集的边界。我尝试了scipy spatial的Delaunay三角剖分,但我得到了以下结果: 当我用这些三角形做alpha形状时,我无法得到点集的边界。所以我认为我应该使用约束Delaunay三角剖分。我选择三角形库来执行此操作。但问题是,我不知道向函数triangle.triangulate(tri,opts='')提供什么。我将所有我更改的点集输入到字典中,但它返回我的点集。那么有人能帮我使用这个功能或其他替代方法来执行轮廓检测吗?谢谢我使用另一个库来实现我的目的:。 下面是如何使
当我用这些三角形做alpha形状时,我无法得到点集的边界。所以我认为我应该使用约束Delaunay三角剖分。我选择三角形库来执行此操作。但问题是,我不知道向函数triangle.triangulate(tri,opts='')提供什么。我将所有我更改的点集输入到字典中,但它返回我的点集。那么有人能帮我使用这个功能或其他替代方法来执行轮廓检测吗?谢谢我使用另一个库来实现我的目的:。 下面是如何使用它对凹面对象进行三角剖分:
from shapely.geometry import MultiPoint
from shapely.ops import triangulate
points=MultiPoint(data)
triangles = triangulate(points)
我不知道三角形库,但您可以使用其他方法来执行此操作 这是一个普遍存在的问题,您可以得到一个简单的代码来解决这个问题。 在算法中,这个问题也称为凸包,scipy中有一个类可用 代码如下,并附有注释
#imports
from scipy.spatial import ConvexHull
import matplotlib.pyplot as plt
## Init graphics
axis = plt.gca(); axis.cla();
#Get points sample
points = np.random.rand(20, 2)
#get Convex hull instance for the points set
hull = ConvexHull(points)
#plor the points
plt.plot(points[:,0], points[:,1], 'v')
#Get and plot the boundary
for simplex in hull.simplices:
axis.plot(points[simplex, 0], points[simplex, 1], 'r-')
结果图可在以下情况后很快看到:
参考文献: