Python 我从scipy.spatial.Delaunay.convertic_hull得到了什么

Python 我从scipy.spatial.Delaunay.convertic_hull得到了什么,python,scipy,spatial,convex-hull,delaunay,Python,Scipy,Spatial,Convex Hull,Delaunay,我认为scipy.spatial.Delaunay.convertic_-hull返回一个数组,其中每个点/索引使用两次,因为一个点属于两条边。但就我而言,有几个指数只有一次: hull = [[5053 6943] [6219 5797] [3441 5797] [7547 1405] [3441 6547] [8144 9215] [ 47 444] [ 444 6219]

我认为scipy.spatial.Delaunay.convertic_-hull返回一个数组,其中每个点/索引使用两次,因为一个点属于两条边。但就我而言,有几个指数只有一次:

hull = [[5053 6943]
        [6219 5797]
        [3441 5797]
        [7547 1405]
        [3441 6547]
        [8144 9215]
        [  47  444]
        [ 444 6219]
        [6547 5053]
        [9945 6943]
        [2695 1405]]

例如,“47”只使用一次。这(几何上)是什么意思?凸包的一个点如何只能用于一条边?

如上所述,您应该使用较新的
scipy.spatial.ConvexHull
。如果您在下面的IPython示例中查看此方法返回的顶点索引,您将看到它们对于2D或3D数据集通常不是冗余的

%pylab inline
import numpy
#use a simple trianglular data set:
triangle_points = numpy.array([[0,0],[-1,1],[1,1]])

#plot the triangle:
fig = plt.figure()
ax = fig.add_subplot(111,aspect='equal')
ax.scatter(triangle_points[...,0],triangle_points[...,1])


Delaunay.convertic_-hull
包含Qhull报告为没有邻居的三角形边。如果三角剖分包含退化三角形,则此集合可以包含人工制品。如果您想获得数值稳定的凸包,请使用
scipy.spatial.ConvexHull
。听起来不错,但我遇到一个错误,不知道原因:
从scipy.spatial导入ConvexHull导入numpy工作点=numpy.array([[0,0],-1,1],[1,1]])conv\u hull=凸包(工作点)conv_hull\u vert=conv_hull.vertices
我得到:
AttributeError:“convxhull”对象没有属性“顶点”
它对我有效--您可能必须使用更新版本的scipy,因为这个版本的convxhull是最近的(当您的注释中的代码有效时,我使用0.13.0)。我发现使用pip是调整安装的scipy版本的最简单方法:
pip install'scipy==0.13.0'
然后
import scipy
scipy.\uu version\uuu
以确保Python访问的版本正确。谢谢。我知道我有版本0.12.0,但我不能测试它,我会稍后再试。但我还有最后一个问题:2D中的
ConvexHull()。顶点
ConvexHull()。simplices
之间有什么区别?我现在也包括了一个simplices示例。您可以看到这里有重复的索引,因为这些是正确的边。这里的标准文档中也对这一点进行了一定程度的描述:
#now calculate the convex hull of the triangular point set:
import scipy, scipy.spatial
convex_hull_2D = scipy.spatial.ConvexHull(triangle_points)
#determine the indices of the vertices forming the convex hull (i.e., the output you get with the older scipy version):
convex_hull_vertex_indices = convex_hull_2D.vertices
#print the array of convex hull vertex indices:
convex_hull_vertex_indices
array([2, 1, 0], dtype=int32) #output

#For this simple 2D data set it is clear that scipy can define a convex hull using the index of each input point only once, so it is not doing AB, BC, CA as you might initially guess

#Let's see what happens if we add a point outside the plane of the triangle and make the data set 3D:
tetrahedral_points = numpy.array([[0,0,0],[-1,1,0],[1,1,0],[0,0.5,3]]) #the last element is the 'out of plane' new point
convex_hull = scipy.spatial.ConvexHull(tetrahedral_points)
convex_hull_vertex_indices = convex_hull.vertices
convex_hull_vertex_indices
array([0, 1, 2, 3], dtype=int32) #output  

#again, for a simple shape, even in 3D, scipy specifies the indices of the vertices of the convex hull in a non-redundant manner

#take a look at the simplices of the 2D ConvexHull object:
convex_hull_simplices = convex_hull_2D.simplices
convex_hull_simplices
array([[2, 1],
       [0, 1],
       [0, 2]], dtype=int32) #output

#so the simplices do contain duplicate indices to connect points to form edges/1-simplices
fig = plt.figure()
ax = fig.add_subplot(111,aspect='equal')
ax.set_ylim(0,1.2)
edge_colors = ['blue','red','green'] #color each 1-simplex differently for clarity
for simplex, edge_color in zip(convex_hull_simplices,edge_colors):
    plt.plot(triangle_points[simplex,0], triangle_points[simplex,1], c=edge_color)