I searched but I could not find a complete answer.
In C# if at all possible.
I need the shortest distance between a WGS point and a WGS point defined line segment on a sphere (Earth exactly).
float DistanceInKilometres(PointF LineStartA, PointF LineEndB, PointF ThePoint)
EDIT: Perhaps an illustration would help

Please note that this is an ideal example. ‘The point’ could be anywhere on the surface of the sphere, the segment start-end, too. Obviously, I’m not looking for the distance through the sphere. Math isn’t my stronger side, so I don’t understand normalize or to cartesian. Maybe I should also note that path AB, is the shortest possible, and Distance?, is the shortest possible too.
You can use the spherical law of cosines:
You will have to use the earth’s radius for calculations:
EARTH_RADIUS_KM = 6371;
Here, from my contributions to OsmMercator.java, from openstreetmap.org:
All you need to do is find the closest point with dot product and use that with the distance equation.
Here’s the closest point example:
Keep in mind the units haven’t been explicitly declared. When dealing with points in space there’re are a variety of ways to determine position. The main thing is you have to nail down your units to a consistent type.
When working with position on the earth, I mainly use lat/long coordinates and vectors for magnitude/direction. There’re are several known types to use for vectors and earth’s position. Among them are the following:
For your example, I might consider sticking to Geodetic.
Now, bringing this together, you might have some pseudo code which looks like this: