Let $P_{1} = (x_1,y_1)$ and $P_{2} = (x_2,y_2)$ be two points in the plane such that $x_{1} \neq x_{2}$ and $y_1 > 0 > y_2$. A particle travels in a straight line from $P_{1}$ to a point $Q$ on the x-axis with speed $v_{1}$, then in a straight line from $Q$ to $P_{2}$ with speed $v_2$. The point $Q$ is allowed to vary. Use Lagrange's method to show that the total travel time from $P_{1}$ to $P_{2}$ is minimized when $\frac{\sin(\theta_{1})}{\sin(\theta_{2})} = \frac{v_{1}}{v_{2}}$, where $\theta_{1}$(resp. $\theta_{2}$) is the angle between the line $P_{1}Q(resp.\ QP_{2})$ and the vertical line through $Q$. Hint: take $\theta_{1}$ and $\theta_{2}$ as the independent variables.
When I first attempted this question I got stuck at a point where I was not given a function and an expression for teh boundary which you are given in easier Lagrange problems. So the first thing I identified was needing to find a function to express this total travel time as well as a function that would characterize my set. I wasn't able to find one, but then eventually our TA provided solutions for the exercise. First he drew the following picture:
I could grasp where this idea came about from, but I am perplexed at the thinking behind creating the function which we are going to minimize:
$$f(\theta_{1},\theta_{2}) = \frac{y_{1}}{v_{1}}\sec(\theta_{1}) + \frac{y_{2}}{v_{2}}\sec(\theta_{2})$$
subject to $g(\theta_{1},\theta_{2}) = 0$, where
$$g(\theta_{1},\theta_{2}) = y_{1}\tan(\theta_{1}) + y_{2}\tan(\theta_{2}) - C$$
where $C = |x_{1} - x_{2}|$.
Of course from here it is a matter of using the Lagrangian procedure.
My question is how did he come up with these two expressions? What was the thought process to arrive at these. I'm stumped and am working on refining my thinking but this one went beyond me at the moment.

$$ \frac{|P_1Q|}{v_1}+\frac{|P_2Q|}{v_2} = T\\ |x_2-x_1| = y_1\tan\theta_1+y_2\tan\theta_2 $$
where $T$ is the time taken from $P_1$ to $P_2$. The restriction is a geometrical limitation. The lagrangian is
$$ L(\theta_1,\theta_2,\lambda) = T+\lambda\left(y_1\tan\theta_1+y_2\tan\theta_2-|x_2-x_1|\right) $$