Point to bounding box directional distance

Distance to AABB at random probe points on a single face.
Depth at a point w.r.t. the machining direction.
Bounding box of a part is covered by depth measures for all feature faces.
int RTCD::IntersectRayAABB(Point p, Vector d, AABB a,
double &tmin, double &tmax)
{
const double EPSILON = RealEpsilon();

tmin = -DBL_MAX; // set to -DBL_MAX to get first hit on line.
tmax = DBL_MAX; // set to max distance ray can travel.

// For all three slabs
for ( int i = 0; i < 3; ++i )
{
if ( Abs(d[i]) < EPSILON )
{
// Ray is parallel to slab. No hit if origin not within slab.
if ( p[i] < a.min[i] || p[i] > a.max[i] )
return 0;
}
else
{
// Compute intersection of ray with near/far plane of slab.
double ood = 1.0f / d[i];
double t1 = (a.min[i] - p[i]) * ood;
double t2 = (a.max[i] - p[i]) * ood;

// `t1` is intersection with near plane, `t2` -- far plane.
if ( t1 > t2 )
std::swap(t1, t2);

// Compute the intersection of slab intersection intervals.
tmin = Max(tmin, t1);
tmax = Min(tmax, t2);

// Exit (no hit) as soon as slab intersection becomes empty.
if ( tmin > tmax )
return 0;
}
}

// Ray intersects all 3 slabs. Return `tmin` and `tmax`.
return 1;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store