954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Ray to Bounding box Intersection

Hi there
I am not sure whether to put this here or in the games development section I do apologies if it is in the wrong the section.

I have an object with a bounding box around it. I want another object to then be able to send a ray out and test to see if the box is within a given range.

I would also like the object generating the ray to be able to constantly change the direction of the ray.

Is there a simple formula that I am missing for doing ray-AABB intersection? I have read about splitting a box into "slabs"?

This seems unnecessary for what I am trying to achieve I simply want to fire a ray and see if it intersects with a box, and at what distance.

Any help would be greatly appreciated

eskimo456
Junior Poster in Training
54 posts since Dec 2010
Reputation Points: 10
Solved Threads: 2
 

Your ray is technically a line, as is the edge of the bounding box. Check if they intersect and where. Then check if the intersection point is within the segment that is the edge of the bounding box. If it is, use the distance between two points formula to find the distance.

Momerath
Nearly a Senior Poster
3,384 posts since Aug 2010
Reputation Points: 1,232
Solved Threads: 558
 

Awesome many thanks got it working now.

Annoyingly easy when you know how :)

eskimo456
Junior Poster in Training
54 posts since Dec 2010
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You