Matlab has built-in functions for calculating reflection and refraction of light according to Snell's Law. Here's an example code snippet to calculate the reflected and refracted angles of photons for given indices of refraction:
667 chars28 lines
In this example, we assume that light travels from medium 1 (e.g., air) to medium 2 (e.g., water). The code calculates the reflected angle and refracted angle based on the incident angle and the indices of refraction of the two media. The angles are output in radians.
gistlibby LogSnag