ricktu288 / ray-optics

A web app for creating and simulating 2D geometric optical scenes, with a gallery of (interactive) demos.
https://phydemo.app/ray-optics/
Apache License 2.0
1.32k stars 220 forks source link

Glass absorbtion [Feature request] #109

Open JeremyLeaf opened 1 year ago

JeremyLeaf commented 1 year ago

Firstly thanks for maintaining this project, it is extremely useful!

Would it be feasible to add an absorbtion setting/parameter to a glass object? So as a ray traverses through the object it gets dimmer due to absorbtion? Maybe this could be achieved by taking the length of a ray within a glass, displaying it with a gradient brightness depending on the length of line.

ricktu288 commented 1 year ago

Two approaches possible here.

  1. Integrate with #69, so that the rays are traced step-wise. This will be quite inefficient if the refractive index and absorption rate are constant (but is the only approach if they are not constant).
  2. As @JeremyLeaf suggested, trace the rays as usual, but the distance that each segment of ray goes is considered.

For 2., we need to add a loop in addRay that checks whether the ray is emerging within each glass. And hence each glass must implement isInsideGlass, etc as currently do for GRIN glasses. These change is also required for #37 and the "source-over body-merging" approach of defining "absolute refractive index" (see #51).