Open sethrj opened 2 years ago
From celeritas-project/celeritas#291:
Maybe the safety could be approximated with a few iterations with steepest descent?
The most promising literature that I could find to date is ON THE DISTANCE FROM A POINT TO A QUADRIC SURFACE. What we need for safety is a sort of "conservative" estimate, ie the returned value can be too low but it must never be too large, I think.
This is a blocking task for celeritas-project/celeritas#181 to calculate the step length.
celeritas-project/celeritas#406 implements the CalcSafetyDistance
algorithm, which works for spheres, planes, and cylinders, since the gradient of those surfaces points to the nearest point on the surface. For any other surfaces, the safety distance is zero (ultra-conservative). For "complex" volumes (those with internal surfaces) the safety distance will be unnecessarily conservative near those internal surfaces.
I finally rediscovered this reference: Hart, Sphere Tracing: A Geometric Method for the Antialiased Ray Tracing of Implicit Surfaces which in Appendix A (pp 5-109–5-110) discusses distance to plane, sphere, cylinder, cone, torus. Distance to an ellipsoid requires solving a sixth degree polynomial.
Per a code review code discussion with @hahnjo, the
CalcSafetyDistance
algorithm (unused but in there as a placeholder) is incorrect. The "safety distance" is a bounding sphere for remaining in the current volume, used to accelerate propagation in a field and multiple scattering. In both cases, the algorithm takes numerous small steps but must not cross a boundary into a different material.