# Simple explanation for ray - AABB intersection?

This topic is 1847 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey everyone,
I've no doubt that this question has been asked countless times (and in fact the search tool confirms my suspicions) yet I ask this question because either the results never truly made sense to me, or that I was looking for a slightly different answer.

Firstly, I've taken a look at this ray-aabb slab method; http://www.cs.utah.edu/~awilliam/box/box.pdf
I suffer two problems here;

1. What is the purpose of t1 and t2? (optimised method) - How would I derive them from an origin and target of a ray?
2. How can I get the hitpoint from this boolean output?

Angus Hollands

##### Share on other sites
My guess is that t1 is the distance in units from the ray origin before ray collisions can occur. You could use it to ignore any collisions if they occur too close to your ray origin - I'm having trouble seeing why you'd ever want to set anything other than zero for it. t2 seems to be the distance in units from the ray origin before ray collisions stop - assuming t1 is zero, then it's the length of the ray.

There are two intersection positions detected, usually you're interested only in the first which is occurs at tmin. To convert that into a position you'd use something like vCollisionPos = r.origin + r.direction * tmin;

##### Share on other sites
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter3.htm

##### Share on other sites

http://www.siggraph....ce/rtinter3.htm

F.Y.I. I looked more closely at the paper today, and I think I had the same reaction you had. WTF?!?

##### Share on other sites

To answer your questions, the t0 and t1 are the starting and ending points of the line segment on the ray.  There is no way to get the hit point from this algorithm.  The point of this is to quickly determine if the ray hits the AABB cube, so that most of the geometry can be rejected.  This isn't what you would use to determine the intersection point, this is what you use to figure out which geometry needs further testing.

##### Share on other sites

Are you sure this is the case? I was told perhaps I could use the cropped values ... Alas, I am going to have to revisit this at a later date!

##### Share on other sites
The way the algorithm is presented in the paper, no. Can you use the local variables to calculate the intersection? I don't know. I didn't spend a lot of time looking at it. I have done this calculation before, but I did it by finding the intersections with all the slabs and then determining if any of the those intersection points are on the cube.

I would need to look at it further. If anyone else knows, please chime in. I will take a guess that the values will give you a point on the ray, but won't tell you which plane of the box was hit or where, which won't be useful because without the plane of the box that was hit you can't calculate a reflection.

Also, I remember the author commenting that this test could give false positives. Maybe that's what this optimized solution is addressing. It is not obvious to me. Edited by Glass_Knife