Ray optics is a geometric model of light. It works when the scale of lenses, interfaces, and paths is much larger than the wavelength and when diffraction can be ignored. A ray diagram is only trustworthy when it labels its interface, normal, refractive indices, and angle convention.
The reflection rule is
\[\theta_{\mathrm{reflection}}=\theta_{\mathrm{incidence}}\]For transmission between ideal media, Snell's law is
\[n_1\sin\theta_1=n_2\sin\theta_2\]If the computed value for sin(θ2) has magnitude greater than one, there is no real transmitted angle in this model. Report total internal reflection instead of calling asin and accepting NaN.
Change the incoming angle and the two refractive indices. The normal is vertical; all reported angles are measured from it.
Reflected angle: 35.0°. Refracted angle: 22.5°.
const sine = (n1 / n2) * Math.sin(incidentAngle);
const transmittedAngle = Math.abs(sine) > 1 ? null : Math.asin(sine);
The null result is an informative physical branch. It tells the UI to draw a reflected ray and explain why no refracted ray is displayed.
Prediction: When light enters a higher-index medium, its ray bends closer to the normal.
Set the incident index to 1.00 and transmitted index to 1.50. Increase the incident angle, predict the refracted angle, and compare it with the labelled result. Then reverse the indices and find a total-internal-reflection case.Ray optics turns an interface into a clear branch: reflect every incident ray, refract when Snell's law has a real solution, and report total internal reflection otherwise. Keep the normal and every angle convention visible.
null a better result than NaN for total internal reflection?Treat the lesson as a small function before treating it as a fact to memorize. Give every value a unit, keep only the state needed for the next step, and make the output easy to inspect.
\[\text{observable output} = f(\text{inputs},\,\text{state})\]For Reflection and Refraction, write down the quantities you can control, the values your program must retain, and the result a reader could inspect. In Geometric and Wave Optics, the useful program is not the drawing: it is the smallest explicit model that makes a prediction you can test.
Prediction: changing one declared input while holding the others fixed should change only the outputs that the model connects to that input. Choose one input, predict the direction of change, then check a limiting case such as zero, a symmetric arrangement, or a familiar low-speed or small-change approximation.
This lesson is a teaching model, not a complete simulator. Before using it outside the stated question, check which interactions, scales, uncertainties, boundary conditions, and measurement limits it leaves out.
Treat Reflection and Refraction as a contract: named inputs and units enter a rule, the rule produces an observable result, and a known limit or invariant checks whether the implementation deserves trust.
Implement optical interface geometry as pure ray updates with normal-incidence tests.