【问题标题】:QuadTree find neighbor四叉树找邻居
【发布时间】:2015-12-01 10:35:54
【问题描述】:

我正在寻找一种算法来查找四叉树的邻居,在示例图像中,我得到了红色节点,如何找到蓝色节点。有任何想法吗?

【问题讨论】:

  • 网址不起作用..
  • 请注意,如果您这样做是为了寻找最近的邻居并且您必须找到很多最近的邻居,您可能会发现 CoverTree 比四叉树更适合您的任务。特别是如果你必须做 k-neighbors 或类似的事情。没关系,如果您将其用于其他目的。

标签: algorithm quadtree


【解决方案1】:

有一些已知的算法。看看他们。

  1. Kunio Aizawa et al. - 四叉树中的恒定时间邻居发现:实验结果
  2. Kasturi Varadarajan - 通过四叉树的所有最近邻居
  3. Robert Yoder, Peter Bloniarz - 在四叉树、八叉树和超八叉树中计算邻居的实用算法

【讨论】:

  • 意识到这是不久前的事了 - 但您是否碰巧记得链接文章的名称或任何内容?由于链接不再有效!
  • 我应该首先把名字放在我的答案中。我的错。该链接现在应该可以工作了。但重点是——用谷歌搜索这样的算法真的很容易。
  • 谷歌找到了你的答案!所以这篇文章是获得相关链接的好地方。谢谢
【解决方案2】:

如果您的语言对数组有很好的支持,并且您可以选择树的表示,那么这会比各种论文建议的简单得多

技巧是将父子关系表示为向量:

def neighbour(tree, node, direction):
    """Finds the neighbour of a node in an adaptive quadtree or it's D-dimensional
    generalization (orthantree?).

    Be very careful with indexing when implementing this. Because it indexes  
    physical space with arrays, sometimes you need to think of coords in terms
    of Euclidean coords, and other times in terms of array coords.

    Args:
        tree: an object holding a bunch of node attributes, indexed by node:
            * `parent`, an (N,)-array of integers. The `n`th element gives the 
               index of `n`'s parent. The parent of the root is -1.
            * `children`, an ((N,) + (2,)*D)-array of integers. The `n`th slice 
               gives the indices of `n`'s children. The bottom-left child of node 3
               in a quadtree would be (3, 0, 0). 
            * `descent`, an (N, D)-array with elements from {-1, +1}. The `n`th
               row gives which direction node `n` lies in compared to its parent.
               For example, the left-bottom quadrant in a quadtree would be `(-1, -1)`.
            * `terminal`, an (N,)-array of booleans. The `n`th element is True
               if node `n` is a leaf.
        node: an integer, the index of the node you want to find the neighbour of.
        direction: a (D,)-array with elements from {-1, +1}

    Returns:
        An integer giving the index of the neighbouring node, or -1 if it doesn't 
        exist.
    """
    direction = np.asarray(direction)

    # Ascend to the common ancestor
    neighbour_descents = []
    while True:
        if (direction == 0).all() or node < 0:
            break
        node_descent = tree.descent[node]
        neighbour_descent = node_descent*(1 - 2*abs(direction))
        neighbour_descents.append(neighbour_descent)

        direction = ((node_descent + direction)/2).astype(int)
        node = tree.parent[node]

    # Descend to the neighbour 
    for neighbour_descent in neighbour_descents[::-1]:
        if tree.terminal[node] or node < 0:
            break
        node = tree.children[(node, *(neighbour_descent.T + 1)//2)]

    return node

它支持比特树 (?)、四叉树、八叉树和一般的 N 维树(超八叉树?orthantree?)。它还支持任何方向 - 基数或对角线。最后,矢量化真的很容易。

灵感来自于 @torvin 发布的来自 Yoder 的基于 FSM 的方法,以及适用于任意数量维度的要求。

There's test and demo code here.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 2017-08-09
    • 2020-01-29
    • 1970-01-01
    相关资源
    最近更新 更多