Solution (source code)

= Solution

Place the interface at $y=0$, with source $(x_A,h_1)$ and observer $(x_B,-h_2)$ in the two uniform media. Let $(s,0)$ be the crossing point. The optical length is
$$
\mathcal S(s)=\mu_1\sqrt{(s-x_A)^2+h_1^2}+\mu_2\sqrt{(x_B-s)^2+h_2^2}.
$$
Differentiating with respect to $s$ and setting the result to zero gives
$$
\mu_1\frac{s-x_A}{\sqrt{(s-x_A)^2+h_1^2}}=\mu_2\frac{x_B-s}{\sqrt{(x_B-s)^2+h_2^2}}.
$$
Recognizing the ratios as the sines of the angles measured from the interface normal proves <Snell's law>:
$$
\boxed{\mu_1\sin\theta_1=\mu_2\sin\theta_2.}
$$
The stationarity condition is the continuity of the tangential optical momentum across the planar interface.