【问题标题】:Is there a direct method of identifying the index of the convex hull points in the original set of points in shapely?有没有直接的方法来识别原始点集中凸包点的索引?
【发布时间】:2021-08-12 10:50:55
【问题描述】:

我有一组点。匀称的convex_hull 方法给了我构成凸包外部的点,没问题。我知道我可以将这些点与原始点集进行比较,然后确定它们在原始点集中的哪个索引,但这在过去产生了错误,我相信它也很慢。那么,有没有什么办法可以识别出凸包点在原始点集合中的索引,而不是把它们从原始集合中拉出来呢?

我的代码目前做了什么:

import numpy as np
import shapely.geometry as spgm

points = np.asanyarray([[0,0],[1,0],[0,1],[1,1],[0.5,0.5]])
points = spgm.MultiPoint(points)
points_ch = points.convex_hull.exterior.coords.xy

In[1]: points_ch
Out[1]: (array('d', [0.0, 0.0, 1.0, 1.0, 0.0]), array('d', [0.0, 1.0, 1.0, 0.0, 0.0]))

我想要输出的是数组的索引。

points_index = points.convex_hull.exterior.index
In[2]: = points_index
Out[2]: = [0,1,2,3]

我寻找索引的原因是因为我想使用凸包点来参考不在凸包中的周围点,以近似局部曲线切线/法线。如果有一个内置函数,它可能会起作用(所以了解它会有所帮助)但同时,我的原始点数据不平滑,我可能不得不尝试不同的平滑计划以获得正确的坡度。我愿意使用其他包进行凸包识别 - 我不需要为我的应用程序使用 shapely。

【问题讨论】:

    标签: python indexing convex-hull


    【解决方案1】:

    事实证明 scipy 可以回答我的问题(尽管如果有人找到了如何正确地做到这一点,那也将是一个有用的答案)。

    from scipy.spatial import ConvexHull
    import numpy as np
    
    points = np.asanyarray([[0,0],[1,0],[0,1],[1,1],[0.5,0.5]])
    hull = ConvexHull(points)
    point_indexes = hull.vertices
    
    In[1]: point_indexes
    Out[1]: array([0, 1, 3, 2], dtype=int32)
    

    它甚至会为你订购。

    【讨论】:

      猜你喜欢
      • 2014-06-29
      • 1970-01-01
      • 2021-08-08
      • 2018-05-07
      • 2013-10-09
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      • 2013-05-09
      相关资源
      最近更新 更多