Let the point be C (Cx,Cy) and the line be AB (Ax,Ay) to (Bx,By).
Let P be the point of perpendicular projection of C on AB. The parameter
r, which indicates P's position along AB, is computed by the dot product
of AC and AB divided by the square of the length of AB:
(1)
AC dot AB
r = ---------
||AB||^2
I think 'r' is "how much of AB" we need to move, from A along the line passing through A and B, to find the point of projection of C on AB. But where does this formula come from? Why AC and AB and why do I need their dot product?