TITLE: Orthogonal projection of a point onto a line
QUESTION [18 upvotes]: How would I go about solving the following problem?

Find an orthogonal projection of a point T$(-4,5)$ onto a line $\frac{x}{3}+\frac{y}{-5}=1$.

REPLY [4 votes]: I wanted to find a direct equation for the orthogonal projection of a point (X,Y) onto a line (y=mx+b). I will refer to the point of projection as as $(X_p,Y_p)$.
Using the same observation, that two orthogonal slopes multiplied together make -1, the slope of the projection line is -1/m and it is also the rise over run for the arbitrary point (X,Y) and the point of projection $(X_p,Y_p)$.
Hence, $\frac {-1} {m} = \frac{Y-Y_p} {X-X_p}$
The unknown is the projection point, so some simple manipulation gets that on one side:
$X_p + mY_p = X + mY$
Knowing that $(X_p,Y_p)$ is on the line, means that $Y_p = mX_p + b$, giving us:
$X_p + m(mX_p + b) = X + mY$
Finally, isolating $X_p$ as:
$X_p = \frac {X + mY - mb} {1+m^2}$
And, through substitution:
$Y_p = \frac {mX + m^2Y + b} {1+m^2}$
Using the point (-4,5) and line definition in the original example we get (noting that the slope of the original line $\frac 5 3$ is approximately 1.667 and the intercept (b) is -5):
$X_p = \frac { -4 + (1.667)(5) - (1.667)(-5)} {1+1.667^2} = 3.3528$
$Y_p = \frac {1.667(-4)+(1.667^2)(5)+(-5)} {1+1.667^2} = 0.589$
which is essentially the same as: $\left(\frac {57}{17},\frac {10}{17}\right)$
The length of the line of projection from (X,Y) to the line y=mx+b can easily be calculated from the two points:
$\sqrt{(Y-Y_p)^2 + (X-X_p)^2}$
But to do it without calculating the point of projection ($X_p$,$Y_p$) first, we can substitute the above equations for $X_p$ and $Y_p$ and obtain:
$\text{length} = \sqrt{\frac {m^2X^2 + Y^2 + b^2 -2bY - 2mXY + 2mbX}  {1+m^2}}$