DCC-Lab / PyTissueOptics

A very simple, fairly slow but very easy to understand and very easy to use Monte Carlo code for Tissue optics simulations.
MIT License
26 stars 5 forks source link

Fix smooth normal at vertices #101

Closed JLBegin closed 11 months ago

JLBegin commented 11 months ago

Issue also known as "pencil rays passing through sphere without intersecting".

Normal smoothing resulted in a NaN normal when incident on a vertex. Fixed by taking the vertex normal when the intersection point is too close to the vertex.

This was an issue when creating a sphere at the origin, with a pencil source propagating along Z. The rays were all passing through some of the primary icosphere mesh vertices (0, 0, -R) and (0, 0, R). The error resulted in the photons passing through without intersecting.

PyMarc2 commented 11 months ago
  1. Is this an issue in the python implementation as well ?
  2. Do you think this might affect the exactitude of meshed lenses in the future?
JLBegin commented 11 months ago

Yes this is also an issue with the Python implementation. I will fix it inside #99 .

This will have no effect on accuracy. The "position == vertex" case is triggered when the length difference if smaller than 1e-6 which is close to the limit of single precision float (1e-7). Converting this position shift 'dx' to a value of angle shift will result in a smaller difference (sin(theta)=dx/r). The error falls under float precision with a radius over 1e-5, which is far from operating conditions.