Box.Contains(Point) == true is not true

I’ve been using Radovan Grmusa’s (@RadovanG) very fast cylinder inclusion test also for boxes.

The way I used it was by defining three center axes (and a cylinder enclosing the box in that direction) and testing for each axis/cylinder, and skipping (break) the first time a point isn’t inside the cylinder.

Unfortunately my final code is a bit “involved” and entangled in a library I had planned to adapt to GPU processing, but in Radovan’s cylinder test is in the link, and well documented. Just nest the axes/cylinder tests to break early, somethiong along these lines:

bool PointInsideBox(Point3d pt, Vector3d axis1, Vector3d axis2, Vector3d axis3)
{
    if not PointInsideCylinder(pt, axis1) return false;
    if not PointInsideCylinder(pt, axis2) return false;
    if not PointInsideCylinder(pt, axis3) return false;
    return true; // is inside
}

The concept looks something like this if illustrated (no rotation is needed to align axes with world, but I have not tested if that would be faster or not, all I know is that this test is quite fast):

Just a crazy idea I had, and it was fast enough for the use case I had at the time.

// Rolf

1 Like