RNBoolean R3Contains(const R3Box& box, const R3Point& point) { // Return whether box contains point if (box.IsEmpty()) return FALSE; if (RNIsLess(point.X(), box.XMin())) return FALSE; if (RNIsLess(point.Y(), box.YMin())) return FALSE; if (RNIsLess(point.Z(), box.ZMin())) return FALSE; if (RNIsGreater(point.X(), box.XMax())) return FALSE; if (RNIsGreater(point.Y(), box.YMax())) return FALSE; if (RNIsGreater(point.Z(), box.ZMax())) return FALSE; return TRUE; }
RNBoolean R3Contains(const R3Box& box, const R3Sphere& sphere) { // Return whether box contains sphere if (box.IsEmpty()) return FALSE; if (sphere.IsEmpty()) return TRUE; if (RNIsLess(sphere.Center().X() - sphere.Radius(), box.XMin())) return FALSE; if (RNIsLess(sphere.Center().Y() - sphere.Radius(), box.YMin())) return FALSE; if (RNIsLess(sphere.Center().Z() - sphere.Radius(), box.ZMin())) return FALSE; if (RNIsGreater(sphere.Center().X() + sphere.Radius(), box.XMax())) return FALSE; if (RNIsGreater(sphere.Center().Y() + sphere.Radius(), box.YMax())) return FALSE; if (RNIsGreater(sphere.Center().Z() + sphere.Radius(), box.ZMax())) return FALSE; return TRUE; }
RNBoolean R3Contains(const R3Box& box1, const R3Box& box2) { // Return whether box1 contains box2 if (box1.IsEmpty()) return FALSE; if (box2.IsEmpty()) return TRUE; if (RNIsLess(box2.XMin(), box1.XMin())) return FALSE; if (RNIsLess(box2.YMin(), box1.YMin())) return FALSE; if (RNIsLess(box2.ZMin(), box1.ZMin())) return FALSE; if (RNIsGreater(box2.XMax(), box1.XMax())) return FALSE; if (RNIsGreater(box2.YMax(), box1.YMax())) return FALSE; if (RNIsGreater(box2.ZMax(), box1.ZMax())) return FALSE; return TRUE; }
RNLength R2Distance(const R2Point& point, const R2Box& box) { // Find axial distances from point to box RNLength dx, dy; if (RNIsGreater(point.X(), box.XMax())) dx = point.X() - box.XMax(); else if (RNIsLess(point.X(), box.XMin())) dx = box.XMin()- point.X(); else dx = 0.0; if (RNIsGreater(point.Y(), box.YMax())) dy = point.Y() - box.YMax(); else if (RNIsLess(point.Y(), box.YMin())) dy = box.YMin()- point.Y(); else dy = 0.0; // Return distance between point and closest point in box if (dy == 0.0) return dx; else if (dx == 0.0) return dy; else return sqrt(dx*dx + dy*dy); }
RNLength R2Distance(const R2Box& box1, const R2Box& box2) { // Find axial distances from box1 to box2 RNLength dx, dy; if (RNIsGreater(box1.XMin(), box2.XMax())) dx = box1.XMin() - box2.XMax(); else if (RNIsGreater(box2.XMin(), box1.XMax())) dx = box2.XMin() - box1.XMax(); else dx = 0.0; if (RNIsGreater(box1.YMin(), box2.YMax())) dy = box1.YMin() - box2.YMax(); else if (RNIsGreater(box2.YMin(), box1.YMax())) dy = box2.YMin() - box1.YMax(); else dy = 0.0; // Return distance between point and closest point in box if (dy == 0.0) return dx; else if (dx == 0.0) return dy; else return sqrt(dx*dx + dy*dy); }
RNBoolean R3Contains(const R3Halfspace& halfspace, const R3Circle& circle) { // Return whether halfspace contains circle RNScalar d = R3SignedDistance(halfspace.Plane(), circle.Center()); if (RNIsNegative(d)) return FALSE; else if (RNIsGreater(d, circle.Radius())) return TRUE; else { RNScalar cos_theta = halfspace.Plane().Normal().Dot(circle.Normal()); if (cos_theta < 0.0) cos_theta = halfspace.Plane().Normal().Dot(-circle.Normal()); return (RNIsGreaterOrEqual(d, cos_theta * circle.Radius())); } }
RNBoolean R3Contains(const R3Cylinder& cylinder, const R3Point& point) { // Get cylinder axis const R3Span& axis = cylinder.Axis(); // Check if outside top or bottom RNScalar t = axis.T(point); if (RNIsNegative(t) || RNIsGreater(t, axis.Length())) return FALSE; // Check if inside radius RNLength d = R3Distance(point, axis.Point(t)); return (RNIsLessOrEqual(d, cylinder.Radius())); }
RNBoolean R3Contains(const R3Cone& cone, const R3Point& point) { // Get cone axis const R3Span& axis = cone.Axis(); // Check if outside top or bottom RNScalar t = axis.T(point); if (RNIsNegative(t) || RNIsGreater(t, axis.Length())) return FALSE; // Check if inside radius RNLength r = (1.0 - t / axis.Length()) * cone.Radius(); RNLength d = R3Distance(axis.Point(t), point); return RNIsGreaterOrEqual(r, d); }