Finding distance to a point from a line defined by two points is well answered, Shortest distance between a point and a line segment . Within that answer http://paulbourke.net/geometry/pointlineplane/ illustrates the line P1, P2 with point P3 tangent to the line showing how to determine distance to that point. This is a GPS application so the heading of the line is already determined and I would like to not use point slope formula or intercept with its limitations.
I would like to determine the point back on the line where the tangent intersects that line from P3 defined by P1 P2. Thank you in advance.
Edit:
I have a solution but its a bit cumbersome, but maybe not, it certainly works:
1) Calculate distance to point by 2 point line to P3 but don't take abs value
2) If distance < 0 then side = 1 else side = -1
3) dist = abs(distance)
4) rad2 = heading + PI/2 * side //tangent is always 90 degrees to line
5) sin rad2*dist + P3.x = point Q.x
6) cos rad2*dist + P3.y = point Q.y
Seems to work no matter the side the point is on