Computing distance from line to point in geodetic environment Supposing to be in a cartesian plan and that I have the following point:
$$A(x_{1},y_{1}),
B(x_{2},y_{2}),
C(x_{3},y_{3}),
D(x_{4},y_{4})$$
$$P(x_{0},y_{0})$$
Now immagine two lines, the fist one ($r_{1}$) passes through the points $A$, $B$ while the second one ($r_{2}$) passes through the points $C$, $D$.
If I want know if $P$ is closer to line $r_{1}$ or $r_{2}$ I think I have follow this approach:
line equation: $y = m*x + q$
So, for the line $r_{1}$ I can calculate $m$ and $q$ in this way:
$$m_{1} = \frac{(y_{2}-y_{1})}{(x_{2}-x_{1})}$$
$$q = y_{1} - m_{1}*x_{1}$$
Then I can calculate the (minimum) distance from $P$ to $r_{1}$:
$$d = \frac{|y_{0}-m_{1}*x_{0}+q|}{(\sqrt{(1+m_{1}^2)})}$$
Than I can apply the same formulas for $r_{2}$ and than I can compare the two distances for determing which is closer ($r_{1}$ or $r_{2}$).
Now, I have translate the same problem in a geodetic environment (earth).
I have the same five points, but in terms of longitude and latitude
$$A(lat_{1},lon_{1}),
B(lat_{2},lon_{2}),
C(lat_{3},lon_{3}),
D(lat_{4},lon_{4})$$
$$P(lat_{0},lon_{0})$$
How can I determine if the point $P$ is closer to the line (actually is a curve) that passes in $A$, $B$ or to the line that passes in $C$, $D$ ?
EDIT:
I think I should to translate the geodetic coordinates into cartesian coordinates:
$$x = R cos\phi cos\theta\\
y = R cos\phi sin\theta\\
z = R sin\phi$$
But now, I need to calculate the distance from $P(x_{0},y_{0},z_{0})$ and the line passing through the points $A$ and $B$ . How can I perform this task?
NOTE: The distance between the poins is in the order of hundreds of meters. 

This link provides code (to be used in conjuction with GeographicLib) to
determine the closest geodesic distance from a point C to a geodesic AB
on an ellipsoid of revolution.  (Note that the program computes the
distance to the AB allowing the geodesic to be extended beyond A and B.
You can easily check when the intercept point lies outside the segment
[AB] and replace the distance with the geodesic distance PA or PB,
whichever is shorter.)  Apply this code to determine the
distance from P to AB and from P to CD.  Then pick the shorter one.
