Solution (source code)

= Solution

<Huygens' principle> treats every point of an advancing <wavefront> as a source of secondary wavelets; their common envelope forms the next wavefront. Consider two points of an incident plane wave reaching the interface at different times. During the same interval $\Delta t$, the remaining incident portion travels $v_1\Delta t$ while the first transmitted wavelet expands a distance $v_2\Delta t$. The two wavefront right triangles share their interface segment, so
$$
\frac{\sin\theta_1}{\sin\theta_2}=\frac{v_1}{v_2}=\frac{n_2}{n_1},\qquad\boxed{n_1\sin\theta_1=n_2\sin\theta_2.}
$$
This is <Snell's law>, with both angles measured from the surface normal. The speeds are phase velocities at the common frequency in stationary isotropic media. If the equation requires $|\sin\theta_2|>1$, there is no propagating refracted ray and <total internal reflection> applies instead.