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.
I have found a solution.
As first step, I translate the geographical coordinate of each point into eculidean space using:
$$x = R cos\phi cos\theta\\ y = R cos\phi sin\theta\\ z = R sin\phi$$
Then all the distances between two points can be calculated as euclidean distance, for example $\overline{AB}$ is:
$$\overline{AB} = \sqrt{(x_{2}-x_{1})^2+(y_{2}-y_{1})^2+(z_{2}-z_{1})^2}$$
Then, considering the triangle composed by the three points: $A$, $B$, $P$. This is a scalene triangle, so I can calculate the high assuming AB segment as base of the triangle.
$$p = \frac{\overline{AB} + \overline{BP} + \overline{PA}}{2} $$
$$\Delta = \sqrt{p(p-\overline{AB})(p-\overline{BP})(p-\overline{PA})}$$
$$ h_{AB} = \frac{2\Delta}{\overline{AB}}$$
Where $p$ is the semi-perimeter of the scalene triangle, $\Delta$ is the area of the triangle from the Erone formula and $h_{AB}$ is the high of the triangle. This high represents also the distance from the the point P to the line passing through $A$ and $B$
As for calculate $h_{AB}$ I can calculate the high $h_{CD}$ so I can compare the two values
$h_{AB} < h_{CD} \implies P $ is closer to the line that passes through $A$ and $B$ points, and vice versa.