Raycast Axis Aligned Bounding Box

Any ray that intersects an AABB will do so twice. The first intersection is where the ray enters the AABB; the second is where the ray exists. If we know both intersection points, the point closest to the origin of the ray is the intersection point.

We can simplify finding the intersections points by visualizing the problem top down. Looking only at the X and Y axis. In this example, the AABB is represented by two slabs. The intersections of the slabs form four planes. These planes represent the faces of the AABB. We cast a ray and check if it's intersecting the X slab:

Raycast Axis Aligned Bounding Box

We found two points as a result of testing the ...

Get Game Physics Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.