【问题标题】:Why a quadtree sometimes need a max number to hold in a node?为什么四叉树有时需要一个最大数量来保存在一个节点中?
【发布时间】:2021-11-05 23:47:54
【问题描述】:

我正在做一个计算几何问题,它使用 C# 库中的 TriangularMeshQuadtree,它的一些构造函数编写如下(来自元数据,所以我看不到实现的细节):

构造函数 1:

// Summary:
    //     Constructor to use if you are going to store the objects in x/y space, and there
    //     is a smallest node size because you don't want the nodes to be smaller than a
    //     group of pixels.
    //
    // Parameters:
    //   xMax:
    //     eastern border of node coverage.
    //
    //   xMin:
    //     western border of node coverage.
    //
    //   yMax:
    //     northern border of node coverage.
    //
    //   yMin:
    //     southern border of node coverage.
    //
    //   maxItems:
    //     number of items to hold in a node before splitting itself into four branch and
    //     redispensing the items into them.
    public TriangularMeshQuadtree(double xMax, double xMin, double yMax, double yMin, int maxItems);

构造函数 2:

//
    // Summary:
    //     Gets quad tree of a list of triangular surface in the plane with normal of dir
    //
    // Parameters:
    //   surfaces:
    //     A list of triangular surface
    //
    //   dir:
    //     The normal of plane on which quad tree is projected
    //
    //   maxItemNumber:
    //     The maximum number of items in each node of quad tree
    //
    //   transformator:
    //     Coordinate transformator
    //
    // Returns:
    //     A quad tree
    public static TriangularMeshQuadtree GetQuadTree(List<SubTSurf> surfaces, Vector3 dir, int maxItemNumber, out CoordinateTransformator transformator);

我对四叉树的理解是,它将一组点递归地划分为 4 个部分,直到每个点在一个部分中都是唯一的。我不明白上述代码中 ma​​xItem 的定义以及它如何与四叉树一起使用。

【问题讨论】:

    标签: quadtree


    【解决方案1】:

    您的理解“......直到每一点在一个部分中都是唯一的”并不完全正确。它描述了一种非常特殊的四叉树,通常用于举例说明这个概念。

    一般来说,四叉树的每个节点可以容纳更多的项目。这通常是为了减少节点的数量(如果我们每个节点的条目比我们需要的节点少)。减少节点数的好处是:

    • 减少内存使用(每个节点都会增加一些内存开销)
    • 通常更快的搜索(每个节点添加一个缓慢的间接),即非常“深”的树的遍历速度很慢。

    maxItem 不应该太大,因为在节点内部,点通常存储在线性列表中。线性列表显然需要线性搜索,因此如果列表太大,这会减慢速度。根据我的经验,maxItem 的合理值在 10 到 100 之间。

    另一个经常给出的参数是maxDepth。此参数限制树的深度,它等于给定节点的父节点数。这个想法是,一个糟糕的数据集可能会导致一棵非常“深”的树,这使得遍历变得昂贵。相反,如果一个节点位于 depth=maxDepth,则即使它超过 maxItem 条目,它也会被阻止分裂。

    综上所述,现实世界中存在有用的四叉树类型结构,每个象限最多允许一个条目。一个例子是 PH 树(免责声明:自我广告)。它使用其他技术将深度限制为 32 或 64。解释需要一段时间,这不是问题的一部分,所以我只是参考documentation here。

    【讨论】:

    • 是的。我使用断点,发现每个节点可以容纳很多点,它的最大数量是maxItem。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 2013-05-24
    • 1970-01-01
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    相关资源
    最近更新 更多