I'm looking for the fastest way to access the mesh cell (i.e. polygon) in a Region
that intersects a Line
in 3D. For example,
reg = BoundaryDiscretizeRegion[Ball[], PrecisionGoal -> 1,
MaxCellMeasure -> 0.1];
Graphics3D[{{Blue, Thick, Line[{{-1, -1, -1}, {0, 0, 0}}]},
Opacity[0.8], reg}, Axes -> True]
Here's a slow naive way:
ps = MeshPrimitives[reg, 2];
intersections =
If[EmptyRegion[3] =!=
RegionIntersection[#, Line[{{0, 0, 0}, {-1, -1, -1}}]], #,
Nothing] & /@ ps;
Graphics3D[{{Red, Line[{{0, 0, 0}, {-1, -1, -1}}]}, intersections},
Axes -> True]
There must be an easy efficient way to find the cell that intersects the line, I'm just not seeing it.