Quadtrees:对于一半的子节点大小意味着什么?

时间:2014-12-31 17:36:45

标签: java data-structures tree quadtree

所以我一直在构建一个四叉树,它们看起来像是非常有趣的对象,似乎有很多用途。因为我一直在我的程序员的帮助下构建树,所以有一件事我不明白。

所以我理解它当然创建了4个节点,但对于一半的子节点大小意味着什么呢?我知道这会让它变小但是这对四叉树有什么好处?如果它没有减半会怎么样?我已经阅读了维基和其他来源,但这是我仍在努力抓住的东西,谢谢你的帮助和建议。 //将子节点大小减半

这是我的构造函数:

public QTreeNode(float centerX,float centerY, float halfWidth, int stopDepth) {
        // set limit with curr depth = to stop depth
        this.currDepth = stopDepth;
        // set Vector to current xyz valyes/ create a vector  with default values 
        this.center = new Vector(centerX,centerY, 0.0f);
        // array is equal to a new array list populated by game objects
        this.objects = new ArrayList<GameObject>();
       // set to default value of 0
        float offsetX = 0.0f;
        float offsetY = 0.0f;

    // if the stopDepth is greater than 0 than if statement continues

    if (stopDepth > 0) {
        // create four child nodes as long as depth > 0
        this.nodes = new QTreeNode[4];
        // halves the child nodes size 
        float step = halfWidth * 0.5f;
        // loop through and create new child nodes
        for (int i = 0; i <4; i++) {
            // compute the offsts of the child nodes
            offsetX = (((i * 1)==0)? step : -step);
            offsetY = (((i * 2)==0)? step : -step);
            nodes[i] = new QTreeNode(centerX + offsetX, centerY + offsetY, step, stopDepth -1);
        }}else {
            this.nodes= null;}}

0 个答案:

没有答案