Search code examples
mathraytracing

Slab-based Ray-box intersection, what's the meaning of Tnear and Tfar in the algorithm?


Actually, I've ever read the algorithm described here: https://education.siggraph.org/static/HyperGraph/raytrace/rtinter3.htm This algorithm can decide whether a ray hit the axis-aligned box.

In the algorithm, it computes the intersection distance of the planes, that is: T1 = (boxmin - o) / d T2 = (boxmax - o) / d boxmin(xl,yl,zl) is the minimum extent of the box and boxmax(xh,yh,zh) is the maximum extent of the box. o(xo,yo,zo) is the origin point of ray and d(xd,yd,zd) is the direction vector of ray. They are all vector3 or float3 variables.

Then the algorithm finds the largest component in T1 and smallest component in T2 and set them to Tnear and Tfar respectively. If Tnear<Tfar, then ray hit the box.

Although it's very elegant, I don't understand why this algorithm can do so, is there any math theory?

I cannot understand why they need the T1 and T2 and why they should be computed like that and what is the meaning of Tfar and Tnear in math. Maybe it seems like we have the equation of line in 3D space, that is, (x-x0)/xd = (y-y0)yd = (z-z0)/zd, and then set x,y,z to boxmin and boxmax. But I'm not sure.

Thanks a lot for explain this for me.


Solution

  • In 3D geometry, t often stands for the position on a line of some point. Lines are often defined by x0 + n*t, where x0 is a point on the line (often the "origin"), and n is the direction vector of the line. t_min and t_max are the t values for two intersection points.. It happens that when t_min < t_max, the line intersected the box, hence their names.