Linetest Axis Aligned Bounding Box

We can use the existing Raycast against the AABB function to check if a line intersects an AABB. Given a line segment with end points A and B, we can create a ray out of the line:

ray.origin = A
ray.direcion = Normalized(B - A);

With this ray, we can perform a Raycast. If the ray intersects the AABB, we check to make sure that the value of t is less than the length of the line. If it is, the segment intersects the Bounding Box:

Linetest Axis Aligned Bounding Box

Getting ready

We are going to implement a function to check if a Line and an AABB intersect. This function will return a Boolean result. We can avoid checking the length of the line segment ...

Get Game Physics Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.