AABB collision

One of the simplest methods of pre-checking whether two objects intersect in space is to check collisions of their bounding objects, in particular AABB (Axis Aligned Bounding Box).

Although the AABB collision check is not very accurate, since it does not take into account the shape of objects at all, it allows excluding objects that are obviously not intersecting from further, more accurate and more expensive checks. This is especially useful when checking complex scenes with many objects.

Consider checking intersections for two parallelograms. The AABB for the parallelogram matches its actual shape, which gives us the ability to visually track their intersections.

Add two cubes to the scene and resize them a bit so that they turn into parallelograms. We can access them from bpy.data:

Translate the coordinates of their points into the global coordinate system to take into account their translations and transformations:

And calculate AABB for each of them using the _aabb() function.

Let’s define a function that will check two AABBs for intersection.

Our function will return True if there is an intersection between the two AABB passed in the parameters, or False if there is no intersection between the AABBs passed in the parameters.

Now we can check if the AABBs for our scene objects intersect:

If there are no intersections of two AABBs, we can guarantee that the objects do not intersect and do not waste time and computer power on more accurate and expensive tests.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comment
Inline Feedbacks
View all comments