【问题标题】:Polygon clusters from List of polygon Neighbors多边形邻居列表中的多边形簇
【发布时间】:2020-06-12 14:15:26
【问题描述】:

我已经实现了这个algorithm 来为每个多边形生成一个相邻多边形的列表。实现工作正常。

现在我打算生成一个多边形簇列表。每个集群都包含共同的邻居:

我有点困惑,试图想出一种算法来将共同的邻居合并到集群中。是否有任何标准算法可以做到这一点?

【问题讨论】:

    标签: algorithm 3d polygon mesh


    【解决方案1】:

    这是一个经典的不相交集union-find 问题。 union-find算法及其相关数据结构支持三种操作:

    • MakeSet(p) 生成一个包含 p 的单例集。
    • Find(p) 其中 p 是宇宙的一个元素(这里是所有多边形的集合),返回一个“可区分元素(多边形)”,它表示包含 p 的整个集合。例如,Find(MakeSet(p))=p。
    • Union(p,q) 将包含 p 和 q 的集合替换为这两个集合的并集,以便之后 Find(p) == Find(q)。如果 p 和 q 已经在同一个集合中,则这是一个空操作。

    现在执行以下算法:

    for each polygon p
      MakeSet(p)
    for each polygon p
      for each polygon q that's a neighbor of p
        Union(p, q)
    Let m be a map from polygons to lists of polygons, intitially empty
    for each polygon p
      append p to map[Find(p)] 
    

    现在地图中的值(多边形列表)就是您的答案。

    Union-Find 算法与按秩并和和折叠查找基本上是常数时间(请阅读 Wikipedia 文章了解反阿克曼函数的理论细节),在实践中非常快,并且易于实现。所有的地图操作也是常数时间。

    因此,该算法的运行速度(基本上)与输入的多边形列表的总和成正比;尽可能快。

    【讨论】:

      【解决方案2】:

      这通常使用depth-first searchbreadth-first search 来完成。

      对于 BFS,您可以执行以下操作:

      Create an empty queue, and assign all polygons to group -1. Set the current group to 0
      While there are any polygons in group -1:
          Randomly grab a polygon which is in group -1 and add it to the queue
          While the queue is not empty:
              Grab the first polygon in the queue and assign it to the current group
              Find all of that polygon's neighbors
                  For all of the neighbors, if they are in group -1, add them to the queue
              Remove the selected polygon from the queue
          Increment the current group
      

      当这个算法完成时,每个多边形将被分配给一个连接组件的集群。

      【讨论】:

        猜你喜欢
        • 2012-02-09
        • 1970-01-01
        • 1970-01-01
        • 2014-12-17
        • 2012-11-09
        • 2018-01-27
        • 2013-02-04
        • 2012-11-07
        • 1970-01-01
        相关资源
        最近更新 更多