Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 如何在python中使用库三角剖分_Algorithm_Python 3.x_Triangulation_Delaunay_Concave Hull - Fatal编程技术网

Algorithm 如何在python中使用库三角剖分

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='')提供什么。我将所有我更改的点集输入到字典中,但它返回我的点集。那么有人能帮我使用这个功能或其他替代方法来执行轮廓检测吗?谢谢我使用另一个库来实现我的目的:。 下面是如何使

我想检测点集的边界。我尝试了scipy spatial的Delaunay三角剖分,但我得到了以下结果:


当我用这些三角形做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-')
结果图可在以下情况后很快看到:

参考文献:


我以前使用过这个库,但我的形状是凹面而不是凸面,这就是为什么凸面外壳没有满足我的需要。Shapely库可以更好地执行任务。