TL;DR
An axis-aligned bounding box (AABB) is the smallest box that holds a shape, where every side of the box is parallel to a coordinate axis. It is stored as just two points, the smallest and largest value on each axis. Because checking whether two such boxes overlap takes only a few comparisons, programs use the box as a cheap stand-in for a complicated shape: if the boxes do not overlap, the shapes cannot either.
Builds on: Vector, coordinate axes · Leads to: Bounding Volume Hierarchy, Collision Detection, Separating Axis Theorem
Where it's used
Video games. A player character, a crate and a tree each have a mesh with thousands of triangles. Testing every triangle against every other one each frame is far too slow. The game gives each object an AABB, tests the boxes first, and runs the detailed mesh test only for pairs whose boxes overlap.
Rendering and culling. Before a renderer draws a model, it checks the model's box against the camera's view. A model whose box lies completely outside the view is skipped, so its triangles never reach the graphics card.
Object detection in images. A detector that finds a car in a photo reports a rectangle around it. That rectangle is an axis-aligned box in image coordinates. Systems measure how well two rectangles agree with the overlap of their areas, and bounding-box regression trains a network to move those rectangles closer to the true objects.
How it works
Take a triangle with corners , and , and compute its box.
-
Find the smallest . The -values are 1, 4 and 2. The smallest is 1. Check: 1 is the left edge of the box.
-
Find the largest . The largest -value is 4. Check: , so the box has positive width.
-
Find the smallest . The -values are 1, 2 and 5. The smallest is 1.
-
Find the largest . The largest is 5. Check: , so the box has positive height.
-
Write the box. It is the rectangle with corners and . Each of the three corners of the triangle lies inside it: is on its corner, is on its right edge, and is on its top edge.
-
Test a second box for overlap. Take the box to . On the -axis, and share the range from 3 to 4. On the -axis, and share the range from 4 to 5. Both axes overlap, so the boxes overlap.
-
Test a third box. Take to . On the -axis, and have no shared value, because 4 is less than 5. The boxes do not overlap, and the test stops.
flowchart TD
A[Two boxes] --> B{Overlap on x?}
B -- no --> N[No overlap]
B -- yes --> C{Overlap on y?}
C -- no --> N
C -- yes --> O[Boxes overlap]
The flowchart is the whole test. In steps 6 and 7 each axis was checked in turn, and the first axis without overlap ends the check.
The math
Definition
Let be a set of points, with coordinates . Its axis-aligned bounding box is the set
where means the product of the intervals, and is the set of numbers from to inclusive. The box is stored as two vectors: its minimum corner with , and its maximum corner with .
Read the formula per axis. The -th coordinate of the box is the interval from the smallest to the largest -th coordinate among the points. This is steps 1 to 5 of the walkthrough, with .
Step 2 in symbols
For the triangle, and . So the -interval is . Similarly the -interval is . The minimum corner is and the maximum corner is .
Overlap in symbols
A point lies inside the box when for every axis . Two boxes and , with corners and , overlap when their intersection is not empty. That happens when every axis overlaps, and an axis overlaps when each interval starts before the other ends:
This is step 6 and step 7 written out. Using rather than means that boxes which just touch at an edge count as overlapping. The test uses comparisons, so it costs a fixed, small amount no matter how many points the shape has.
Why this is a safe first test
If the boxes do not overlap, the shapes inside them cannot touch, because each shape lies entirely inside its own box. The converse fails: two boxes can overlap while the shapes inside them do not, which is why a second, more exact test is still needed.
Worked examples
Three points on a line have coordinates 2, 7 and 4.
- Smallest coordinate: 2. Largest coordinate: 7. So the box is .
- Is the point 5 inside? Check . Yes.
- Compare with the interval . Overlap needs and . Both are true, so and overlap, and the shared range is .
- Compare with . Overlap needs . That is false, so there is no overlap.
Interpretation: on a single axis, the box is just the range from the smallest to the largest value, and overlap means the two ranges share at least one value.
Triangle has vertices , and . Triangle has vertices , and .
- Box of : values 0, 2, 1 give . values 0, 1, 3 give . So .
- Box of : values 3, 5, 5 give . values 1, 1, 4 give . So .
- Overlap on : need and . The second is false.
- So the -intervals do not overlap, and the boxes do not overlap.
- Conclusion: the triangles cannot touch. No triangle-to-triangle test is needed.
Interpretation: the -intervals and do overlap, but one axis without overlap is enough to rule out a collision.
A game uses metres. The player's box is and . Crate A's box is and . Crate B's box is and .
- Player against crate A, axis: need and . Both hold, so the -ranges overlap.
- Player against crate A, axis: need (the player's minimum against crate A's maximum). This is false, so the -ranges do not overlap.
- Conclusion: the player and crate A do not collide. The game skips the detailed check.
- Player against crate B, axis: as in step 1, the -ranges overlap.
- Player against crate B, axis: need and . Both hold, so the -ranges overlap.
- Both axes overlap, so the boxes overlap. The game runs the detailed mesh test for the player and crate B only.
Interpretation: two checks eliminated crate A without touching its geometry, and the expensive test ran for one crate. In a game with thousands of objects, this is what keeps the frame rate steady.
Try it: Does the player's box overlap crate A's box if crate A's top is raised to ? Answer: yes. The check becomes on the axis, which is true because accepts equal values, so boxes that just touch count as overlapping.
Common mistakes and tradeoffs
It is tempting to think that two overlapping boxes mean the shapes collide. In fact the box test only says the shapes might collide. A thin diagonal bar placed in the corner of a box can be far from another object that sits in the box's other corner, so the boxes overlap and the shapes do not. The box test is a filter, and a detailed test must follow.
It is tempting to think that a box stays small when the shape rotates. In fact it grows: a square rotated by 45 degrees has an axis-aligned box about 41 percent larger on each side than the square's side length, so the box must be recomputed after rotation. An oriented box, which rotates with the shape, is tighter but costs more to test.
It is tempting to treat touching boxes and separated boxes as the same. In fact the comparison must be chosen on purpose. Using instead of makes boxes that touch count as separate, which can be right for some games and wrong for others.
When to use an AABB: many objects, a cheap first filter, and shapes that are roughly round or box-shaped.
When not to use it: long thin shapes that rotate often, where the box is much larger than the shape and the filter lets too many false pairs through. Then use an oriented box, a bounding sphere, or the Separating Axis Theorem for exact convex shapes.
History
Bounding volumes entered computer graphics in the 1970s. In 1976 James Clark proposed organising a scene's geometry into a hierarchy of bounding volumes, so that large groups could be tested or skipped at once. Boxes aligned with the axes became the common choice because the overlap test needs only a few comparisons, which mattered on the slow hardware of the time. The same idea carried into real-time games, where it is still used as the first stage of collision detection.
Recap
- An AABB is the smallest axis-parallel box around a set of points. It is stored as a minimum corner and a maximum corner.
- The box on each axis is the interval from the smallest to the largest coordinate.
- Two boxes overlap when every axis's intervals overlap, which takes a few comparisons per axis.
- Non-overlapping boxes prove non-collision. Overlapping boxes only suggest collision, so a detailed test is still needed.
What to read next: the Bounding Volume Hierarchy stores boxes in a tree, so that whole groups are skipped at once. The Collision Detection lesson shows the full pipeline from boxes to exact contact, and the Separating Axis Theorem gives an exact test for convex shapes.
Check yourself
QuestionA set of points on a line has coordinates 3, -1, 6 and 0. What is its axis-aligned box?Show answer
The smallest coordinate is and the largest is 6, so the box is the interval .
QuestionBox and box . Do they overlap?Show answer
On : need and . Both hold. On : need and . The second is false. So the -intervals do not overlap, and the boxes do not overlap, even though they touch in the direction.
QuestionA box has minimum corner and maximum corner . Is the point inside it?Show answer
Check each axis: holds, and holds. Both hold, so the point lies inside the box, on its edges.
QuestionA square of side 2 is axis-aligned and centred at the origin. It is rotated by 45 degrees. Explain why its axis-aligned box is larger, and give the side length of the new box.Show answer
A square rotated by 45 degrees has its corners at the points and . The box must contain all four, so it runs from to on each axis. Its side length is , bigger than the original side of 2. The rotated shape fills less of its box, so the box is wider than the square.
QuestionIn a game, the box test says two objects overlap but they are visibly apart. Why, and what should the program do next?Show answer
A box is larger than the shape it holds, so the overlap may come from empty corners of the boxes. The box test is only a filter that says the shapes might touch. The program should run an exact test on the shapes themselves, such as the separating-axis test for convex shapes, before deciding that they collide.