# Counting AABB for object in Blender

For quick and rough checking of two objects geometry intersections, bounding objects are usually used – spheres or parallelograms in which all points of the object are inscribed. Bounding object intersections are often inaccurate, but they are very efficient in terms of speed. One of the types of bounding objects is AABB (Axis Aligned Bounding Box) – a parallelogram aligned with the global coordinate axes. Each object in Blender always has a bounding box already calculated. It can be seen in the 3D Viewport area by checking the “Bounds” checkbox in the Object Properties panel in the Properties area. But this parallelogram is not aligned with the global axes, which makes it slightly slower in calculations. For an axis-aligned bounding box (AABB), we can calculate the required points ourselves.

At first, we need to recalculate all object vertices coordinates into the global coordinate system by multiplying their local coordinates by the world matrix of the object.

Now let’s define a function to find the minimum and maximum values of the coordinates along the X, Y and Z axes. The function will return us the coordinates of two points at the ends of the main AABB diagonal.

In the function parameter, we pass a list of coordinates of the object’s vertices in the global coordinate system.

Inside the function, we first split the list of vertices coordinates into three separate lists, in which we placed separately the coordinates along the X, Y and Z axes.

The minimum and the maximum values in each of the lists will be the coordinates of the end points of the main AABB diagonal that we are looking for.

The coordinates of these two points of AABB are enough to get the coordinates of all its other points.

Let’s create an object in the scene built according to the obtained coordinates.

Define the “vertices” list with eight AABB vertices coordinates and the “edges” list – set of vertices indices to build edges:

Create a mesh according to the defined geometry and add it to the scene: Now we clearly see that the bounding parallelogram built according to our calculations completely fits into the original object and is aligned with the global coordinate axes. So this parallelogram is the real AABB for the initial object. 