Reference Blog:
https://www.cnblogs.com/lyggqm/p/4651979.html
By calculating vector, calculating point to line segment through comparing two values to calculate three probabilities of point, inside line segment, left and right sides of line segment. Through calculation can fast find distance from point to line segment. Specific theory refer to blog given.
In Revit secondary development, need to find shortest distance from point to line segment. In API there is Curve.Distance can find, can also use trigonometric function to find angle but this method is not fully tested, always feel there will be troublesome places. When finding shortest distance, use vector method to find reversed line segment distance. When point is outside line segment, will take out triangle long side c, at this time can find angle α of both, use trigonometric function again to take out perpendicular side, get shortest distance.

Shortest distance a between target point A and line segment BP