我在 numpy 中有一组点,我通过 (scipy.spatial.ConvexHull 而不是 scipy.spatial.Delaunay.convex_hull) 计算它们的 ConvexHull,现在我想知道我是否向我的数组添加新点是这个点位于点云与否?在 numoy 中最好的方法是什么?
我应该提到我看到了这个问题并且它没有解决我的问题(因为它使用 cipy.spatial.Delaunay.convex_hull 来计算 ConvexHull)
I know this question is old, but in case some people find it as I did, here is the answer: I'm using scipy 1.1.0 and python 3.6
def isInHull(P,hull):
'''
Datermine if the list of points P lies inside the hull
:return: list
List of boolean where true means that the point is inside the convex hull
'''
A = hull.equations[:,0:-1]
b = np.transpose(np.array([hull.equations[:,-1]]))
isInHull = np.all((A @ np.transpose(P)) <= np.tile(-b,(1,len(P))),axis=0)
Run Code Online (Sandbox Code Playgroud)
Here we use the equations of all the plan to determine if the point is outside the hull. We never build the Delaunay object. This function takes as insput P mxn an array of m points in n dimensions. The hull is constrcuted using
hull = ConvexHull(X)
Run Code Online (Sandbox Code Playgroud)
where X is the pxn array of p points that constitute the cloud of points on which the convex hull should be constructed.
| 归档时间: |
|
| 查看次数: |
2210 次 |
| 最近记录: |