In computer graphics, the slab method is an algorithm used to solve the ray-box intersection problem in case of an axis-aligned bounding box (AABB), i.e. to determine the intersection points between a ray and the box. Due to its efficient nature, that can allow for a branch-free implementation, it is widely used in computer graphics applications.
The idea behind the algorithm is to clip the ray with the planes containing the six faces of the box. Each pair of parallel planes defines a slab, and the volume contained in the box is the intersection of the three slabs. Therefore, the portion of ray within the box (if any, given that the ray effectively intersects the box) will be given by the intersection of the portions of ray within each of the three slabs.
A tridimensional AABB can be represented by two triples
\boldsymboll=(l0,l1,l2)
\boldsymbolh=(h0,h1,h2)
\boldsymbolp(t)=(p0(t),p1(t),p2(t))
\boldsymbolo=(o0,o1,o2)
\boldsymbolr=(r0,r1,r2)
\boldsymbolp(t)=\boldsymbolo+t\boldsymbolr
Assuming that all intersections exist, i.e.
ri\ne0 \foralli
t
t=
\boldsymbolp-\boldsymbolo | |
\boldsymbolr |
and therefore the two intersections of the ray with the two planes orthogonal to the
i
low | |
\begin{align} t | |
i |
&=
li-oi | |
ri |
high | |
\\ t | |
i |
&=
hi-oi | |
ri |
. \end{align}
The close and far extrema of the segment within the
i
close | |
\begin{align} t | |
i |
&=min\left\{
low | |
t | |
i |
,
high | |
t | |
i |
\right\}
far | |
\\ t | |
i |
&=max\left\{
low | |
t | |
i |
,
high | |
t | |
i |
\right\} \end{align}
and the intersection of all these segments is
\begin{align} tclose&=maxi\left\{
close | |
t | |
i |
\right\}\\ tfar&=mini\left\{
far | |
t | |
i |
\right\}. \end{align}
Such resulting segment will be inside the box, and therefore an intersection exists, only if
tclose\letfar
tclose
\begin{align} \boldsymbolpclose&=\boldsymbolo+tclose\boldsymbolr\\ \boldsymbolpfar&=\boldsymbolo+tfar\boldsymbolr. \end{align}
While the equations above are well defined for real-valued variables only if
ri\ne0 \foralli
t=+infty
t=-infty
i
ti=
0 | |
0 |