Working through some exercises on Variational Calculus from Taylor's Classical Mechanics.

I'm not entirely sure how to set this up.

I had a look at past post "

Does Fermat principle explain refraction inside water?" but the problem seemed to be subtlely different.

I can see that the distance $\displaystyle \left | \overrightarrow{P_1 Q} \right | = \sqrt{x^2+h_1^2+z^2}$ and $\displaystyle \left | \overrightarrow{Q P_2} \right | = \sqrt{(x_2-x)^2+h_2^2+z^2}$

I imagine we set up the Lagrangian as $\displaystyle \mathcal{L} = \left | \overrightarrow{P_1 Q } \right | + \left | \overrightarrow{Q P_2} \right | $ and then find stationary conditions with respect to x and z. (Bit fuzzy about that part).

However, my immediate problem is that I am not sure how to work $\displaystyle n_1$ and $\displaystyle n_2$ into the problem.

Any thoughts.