# AABB Ray collision confusion

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

## Recommended Posts

So I've been looking around for a good ray - box collision detection methood and I recently found one. http://www.cs.utah.edu/~awilliam/box/ (the pdf) I was looking at the function, which looks something like this I'm just confused on what to pass as an argument for t0 and t1. The paper called those arguments "valid intersection intervals"


bool Box::intersect(const Ray &r, float t0, float t1) const {
float tmin, tmax, tymin, tymax, tzmin, tzmax;

tmin = (parameters[r.sign[0]].x() - r.origin.x()) * r.inv_direction.x();
tmax = (parameters[1-r.sign[0]].x() - r.origin.x()) * r.inv_direction.x();
tymin = (parameters[r.sign[1]].y() - r.origin.y()) * r.inv_direction.y();
tymax = (parameters[1-r.sign[1]].y() - r.origin.y()) * r.inv_direction.y();
if ( (tmin &gt; tymax) || (tymin &gt; tmax) )
return false;
if (tymin &gt; tmin)
tmin = tymin;
if (tymax &lt; tmax)
tmax = tymax;
tzmin = (parameters[r.sign[2]].z() - r.origin.z()) * r.inv_direction.z();
tzmax = (parameters[1-r.sign[2]].z() - r.origin.z()) * r.inv_direction.z();
if ( (tmin &gt; tzmax) || (tzmin &gt; tmax) )
return false;
if (tzmin &gt; tmin)
tmin = tzmin;
if (tzmax &lt; tmax)
tmax = tzmax;
return ( (tmin &lt; t1) && (tmax &gt; t0) );
}


Can someone explain to me what to pass as t0 and t1? Thanks

##### Share on other sites
It looks like those values are a needless complication. tMin and tMax are the values you're interested in returning. They should be stored in output parameters.

Any "t" values represents the "time" along the ray, this represents the distance along the ray to some point.

P(t) = rayOrigin + rayDirection * t;

When the ray passes through a box shape there will be two points it intersects. These points will be stored as t values as tmin (the face it first hits/enters) and tmax (the second face where it exits).

If the ray intersected an edge, tmin and tmax should equal each other.

To make the result a boolean, they allowed you to pass in a "valid interval" for tmin and tmax to be compared to.

If a time values is less than zero, it lies before the start of the ray, in the negative rayDirection. If the time value is greater than 1, it lies after the end of rayDirection

Last but not least, if rayDirection is of unit length then time is equivalent to distance.

##### Share on other sites
usually, t0 is set to '0', and t1, to the ray 'length'.

1. 1
2. 2
3. 3
Rutin
25
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633648
• Total Posts
3013113
×