Hola:
La idea la de
Luis Fuentes es muy buena y parece resolver el problema; por mi parte, tomando como origen el extremo inferior izquierdo, me he ocupado en asignar unas coordenadas a los puntos de la figura,
en la que aparecen las dimensiones de la caja \( 2a\times b \), la posición inicial \( A(x_0,y_0) \) y la separación de los medios en la mitad de la caja. Una vez hecho esto, y si no me he equivocado, creo que bastaría con imponer la condición de que \( \tan(90^{\circ}-\theta_1) \) es igual a la pendiente de la recta de vector director \( \vec{GA} \) y usar el hecho de que \( \theta_2=\arcsen \left(\dfrac{n_1\sen\theta_1}{n_2}\right) \).
\( A(x_0,y_0)\\
B(x_0+(a-y_0)\tan\theta_1,a)\\
C(x_0+(a-y_0)\tan\theta_1+\tan\theta_2,2a)\\
D\left(b,2a-\dfrac{b-[x_0+(a-y_0)\tan\theta_1+a\tan\theta_2]}{\tan\theta_2}\right)\\
E\left(b-\tan\theta_2\left(a-\dfrac{b-[x_0+(a-y_0)\tan\theta_1+a\tan\theta_2]}{\tan\theta_2}\right)-a\tan\theta_1,0\right)\\
G\left(0,\dfrac{b-\tan\theta_2\left(a-\dfrac{b-[x_0+(a-y_0)\tan\theta_1+a\tan\theta_2]}{\tan\theta_2}\right)-a\tan\theta_1}{\tan\theta_1}\right) \)
Por tanto, \( \vec{GA}=\left(x_0,y_0-\dfrac{b-\tan\theta_2\left(a-\dfrac{b-[x_0+(a-y_0)\tan\theta_1+a\tan\theta_2]}{\tan\theta_2}\right)-a\tan\theta_1}{\tan\theta_1}\right) \) con lo que
\( \tan(90^{\circ}-\theta_1)=\dfrac{y_0-\dfrac{b-\tan\theta_2\left(a-\dfrac{b-[x_0+(a-y_0)\tan\theta_1+a\tan\theta_2]}{\tan\theta_2}\right)-a\tan\theta_1}{\tan\theta_1}}{x_0} \)
Y a esperar...
Saludo