Home

rayAABB

rayAABB is a common test in computer graphics and computational geometry that determines whether a parametric ray intersects an axis-aligned bounding box (AABB) in 3D space. It is widely used in ray tracing, visibility queries, and broad-phase collision detection to quickly cull objects that do not intersect a ray, improving performance.

An AABB is defined by its minimum and maximum corners (xmin, ymin, zmin) and (xmax, ymax, zmax).

From these, define tmin_axis = min(t1, t2) and tmax_axis = max(t1, t2) for each axis, then overall tmin

Variations include using the reciprocal of D for faster computation and precomputing sign information to branch-freely

A
ray
is
given
by
origin
O
and
direction
D,
with
the
parametric
form
R(t)
=
O
+
tD
for
t
>=
0.
The
slab
method
computes
intersection
intervals
along
each
axis
by
solving
for
t
where
the
ray
intersects
the
bounding
planes
of
the
box.
For
each
axis,
compute
t
values
where
the
ray
meets
the
slabs:
t1
=
(min
-
O_axis)
/
D_axis
and
t2
=
(max
-
O_axis)
/
D_axis.
If
a
component
of
D
is
zero,
the
ray
is
parallel
to
that
axis;
intersection
is
possible
only
if
the
origin
coordinate
lies
within
the
slab
for
that
axis.
=
max(tmin_x,
tmin_y,
tmin_z)
and
tmax
=
min(tmax_x,
tmax_y,
tmax_z).
The
ray
intersects
the
box
if
tmax
>=
tmin
and
tmax
>=
0.
The
entry
distance
along
the
ray
is
tHit
=
tmin
if
tmin
>=
0,
otherwise
tHit
=
tmax
if
tmax
>=
0.
If
neither
condition
holds,
there
is
no
intersection.
select
slab
intersections.
Implementations
may
return
a
boolean
intersection
flag
and
optionally
the
near
and
far
intersection
distances
(tNear
and
tFar).
Common
pitfalls
include
handling
rays
parallel
to
an
axis
and
degenerate
or
inverted
boxes.