# Closest point on line segment of a great circle

If I have a sphere of radius R, and two points $$A$$ and $$B$$ on its surface, at $$(R, \theta_A,\phi_A)$$ and $$(R, \theta_B,\phi_B)$$ respectively in spherical coordinates. Call $$AB$$ the geodesic from $$A$$ to $$B$$, i.e. the segment of the great circle connecting the two points.

Given a third point $$P$$ at $$(R, \theta_P,\phi_P)$$, how can I find out the point $$Q \in AB$$ which is closest to $$P$$ (in the geodesic sense)?

There are a couple of online references.

Mathoverflow
https://mathoverflow.net/questions/101776/altitudes-of-a-triangle
There is a more extensive theory at:
https://www.researchgate.net/publication/305401152_Projective_configuration_theorems_old_wine_into_new_wineskins
page 29. And, no I haven't read the whole article :) but it looks powerful.
Setting R=1.
The “$$\times$$” product below is the normal cross product normalized to 1.
Here is an intuitive method using the picture below with C taking the place of P.
Consider the great circle passing through $$A,B$$ and say that the Cartesian coordinates of $$A,B,C$$ are $$\left[a_{x},a_{y},a_{z}\right],\left[b_{x},b_{y},b_{z}\right],\left[c_{x},c_{y},c_{z}\right]$$
Call the great circle the “equator”.
Define the “North pole” $$N$$ as the intercept of $$A\times B$$ with the spherical surface; i.e. normalized.
Now every great circle passing through the North pole is a geodesic path intercepting the equator.
Thus the polar great circle through $$C$$ gives the geodesic altitude of $$C$$ above the equator at $$Q$$.
At this point, we could revert to Spherical coordinates and find $$Q$$.
Alternately we can stay with Cartesian coordinates.
We observe that the vector to Q is orthogonal to the axes of the great circles $$A,B$$ and $$\text{N,C }$$ giving $$Q=\left(A\times B\right)\times\left(\left(A\times B\right)\times C\right)$$

This can be rephrased by means of compounded vector triple product. 