• Create Account

## Simple explanation for ray - AABB intersection?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

### #1Angus Hollands  Members

858
Like
0Likes
Like

Posted 18 December 2012 - 02:34 PM

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;
• What is the purpose of t1 and t2? (optimised method) - How would I derive them from an origin and target of a ray?
• How can I get the hitpoint from this boolean output?
Angus Hollands

### #2C0lumbo  Members

4065
Like
0Likes
Like

Posted 18 December 2012 - 02:48 PM

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;

### #3Glass_Knife  Moderators

8600
Like
0Likes
Like

Posted 18 December 2012 - 04:59 PM

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Book: http://amzn.com/1305076532

### #4Glass_Knife  Moderators

8600
Like
0Likes
Like

Posted 19 December 2012 - 01:33 PM

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

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Book: http://amzn.com/1305076532

### #5Glass_Knife  Moderators

8600
Like
0Likes
Like

Posted 21 December 2012 - 09:33 AM

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.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Book: http://amzn.com/1305076532

### #6Angus Hollands  Members

858
Like
0Likes
Like

Posted 03 January 2013 - 02:43 PM

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!

### #7Glass_Knife  Moderators

8600
Like
0Likes
Like

Posted 03 January 2013 - 03:17 PM

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, 03 January 2013 - 03:19 PM.

I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming