首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AABB的划分

AABB的划分
EN

Stack Overflow用户
提问于 2014-03-11 15:01:23
回答 1查看 712关注 0票数 2

我遇到了一个问题,我需要将AABB划分为多个小型AABB。我需要在每个较小的AABB中找到最小和最大的点。

如果我们以这个长方体为例,我们可以看到它被分成64个较小的长方体。我需要计算所有这些小长方体的最小和最大点,其中长方体的数量(64)可以指定的最终用户。

我对以下代码进行了基本尝试:

代码语言:javascript
复制
// Half the length of each side of the AABB.
float h = side * 0.5f;

// The length of each side of the inner AABBs.
float l = side / NUMBER_OF_PARTITIONS;

// Calculate the minimum point on the parent AABB.
Vector3 minPointAABB(
    origin.getX() - h,
    origin.getY() - h,
    origin.getZ() - h
);

// Calculate all inner AABBs which completely fill the parent AABB.
for (int i = 0; i < NUMBER_OF_PARTITIONS; i++)
{
    // This is not correct! Given a parent AABB of min (-10, 0, 0) and max (0, 10, 10) I need to
    // calculate the following positions as minimum points of InnerAABB (with 8 inner AABBs).
    // (-10, 0, 0), (-5, 0, 0), (-10, 5, 0), (-5, 5, 0), (-10, 0, 5), (-5, 0, 5), 
    // (-10, 5, 5), (-5, 5, 5)

    Vector3 minInnerAABB(
        minPointAABB.getX() + i * l,
        minPointAABB.getY() + i * l,
        minPointAABB.getZ() + i * l
    );

    // We can calculate the maximum point of the AABB from the minimum point 
    // by the summuation of each coordinate in the minimum point with the length of each side.
    Vector3 maxInnerAABB(
        minInnerAABB.getX() + l,
        minInnerAABB.getY() + l,
        minInnerAABB.getZ() + l
    );

    // Add the inner AABB points to a container for later use.
}

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-11 18:47:29

我想你的问题是你没有足够的子盒子。分区的数量指的是每个维度的分区,对吗?因此,两个分区产生8个子框,3个分区生成27个子框,以此类推。

然后必须有三个嵌套循环,每个维度一个:

代码语言:javascript
复制
for (int k = 0; k < NUMBER_OF_PARTITIONS; k++)
    for (int j = 0; j < NUMBER_OF_PARTITIONS; j++)
        for (int i = 0; i < NUMBER_OF_PARTITIONS; i++)
        {
            Vector3 minInnerAABB(
                minPointAABB.getX() + i * l,
                minPointAABB.getY() + j * l,
                minPointAABB.getZ() + k * l
            );

            Vector3 maxInnerAABB(
                minInnerAABB.getX() + l,
                minInnerAABB.getY() + l,
                minInnerAABB.getZ() + l
            );

            // Add the inner AABB points to a container for later use.
        }
    }
}

或者,您可以在分区立方体上有一个巨大的循环,并通过循环中的除法和余数操作来排序索引,这对于三维来说有点混乱。

通过根据原始框的边长计算每个维度的三个独立的子框长度,使代码更加通用也可能是一个好主意。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22329545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档