2

I have a problem where I need to divide an AABB into a number of small AABBs. I need to find the minimum and maximum points in each of the smaller AABB.

enter image description here

If we take this cuboid as an example, we can see that is divided into 64 smaller cuboids. I need to calculate the minimum and maximum points of all of these smaller cuboids, where the number of cuboids (64) can be specified by the end user.

I have made a basic attempt with the following code:

// 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.
}

Many thanks!

  • @user2079303 The OP ask for an algorithm, I've edited the tags. – πάντα ῥεῖ Mar 11 '14 at 15:08
  • 1
    No idea what this question is asking for. – G. Bach Mar 11 '14 at 15:12
  • AABB = axis-aligned bounding box. Is the size of the sub AABB given as part of the problem statement? As it is, you could just pick a side lengths that divide the corresponding lengths in the outer box. The challenge would lie in trying to find an AABB that encloses a given set of points in the interior of the larger box. – chepner Mar 11 '14 at 15:16
  • @G.Bach: "American association of blood banks" – hivert Mar 11 '14 at 16:36
  • 1
    Please don't ever give code without giving some explanation for it (not just comments). You have a "This is not correct!" comment which is presumably similar to what you should put outside the code, except that you should also include what the code is actually doing, rather than just what you want it to do. Also, why did you remove the image? This question is rather cryptic without it. And don't assume everyone is familiar with your abbreviations - write the full term out at least once. – Bernhard Barker Mar 11 '14 at 18:08
  • Even given an explanation for AABB, I can't figure out what George is trying to do. What is a minimum/maximum point in a cuboid? How is this related to rubix cubes, and why is that relevant here? Are you trying to partition the AABB or are you just trying to create some AABBs within it? Do they need to be overlap free? – G. Bach Mar 11 '14 at 18:24
  • Sorry, I've updated the question. I hope this explains it better! –  Mar 13 '14 at 00:39

1 Answers1

0

I assume that your problem is that you don't get enough sub-boxes. The number of partitions refers to partitions per dimension, right? So 2 partitions yield 8 sub-boxes, 3 partitions yield 27 sub-boxes and so on.

Then you must have three nested loops, one for each dimension:

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.
        }
    }
}

Alternatively, you can have one huge loop over the cube of your partitios and sort out the indices by division and remainder operations inside the loop, which is a bit messy for three dimensions.

It might also be a good idea to make the code more general by calculating three independent sub-box lengths for each dimension based on the side lengths of the original box.

M Oehm
  • 28,726
  • 3
  • 31
  • 42