Orthogonal projection of a point onto a line 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$.

 A: 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}}$
A: I'd like to solve the problem using orthogonal projection matrices.
If the line is passing through the origin, it will be very simple to find the orthogonal projection. Suppose $p$ is the given point, $v$ is the given line (passing through the origin, so represented by a vector). Then the orthogonal projection point is
$$\frac{vv^T}{v^Tv}p$$
Now the given line does not pass through the origin. But it can be convert to the simple problem above. Choose a point $p_0=(x_0,y_0)^T$ on the given line. Move the origin to $p_0$ (later move back). Then the line can be represented by a vector $v$, and the original given point becomes $p_1=p-p_0$. Now compute $\frac{vv^T}{v^Tv}p_1$. Then move the origin back, we get the orthogonal projection in the original coordinate system is 
$$\frac{vv^T}{v^Tv}(p-p_0)+p_0=\frac{vv^T}{v^Tv}p+\left(I-\frac{vv^T}{v^Tv}\right)p_0$$.

Specifically, for your problem, $p=(-4,5)^T$. Choose $p_0=(0,-5)^T$, then
$$\frac{vv^T}{v^Tv}p+\left(I-\frac{vv^T}{v^Tv}\right)p_0=(\frac{57}{17},\frac{10}{17})^T$$
A: The slope of the line $r$, with equation $\frac{x}{3}+\frac{y}{-5}=1$, is $m_{r}=\frac{5}{3}$ (because $\frac{x}{3}+\frac{y}{-5}=1$ is equivalent to $y=\frac{5}{3}x-5$). The slope of the line $s$ orthogonal to $r$ is $m_{s}=-\frac{3}{5}$ (because $m_{r}m_{s}=-1$). Hence the equation of $s$ is of the form
$$y=-\frac{3}{5}x+b_{s}.$$
Since $T(-4,5)$ is a point of $s$, we have 
$$5=-\frac{3}{5}\left( -4\right) +b_{s},$$ 
which means that $b_{s}=\frac{13}{5}$. So the equation of $s$ is
$$y=-\frac{3}{5}x+\frac{13}{5}.$$

The coordinates of the orthogonal projection of $T$ onto $r$ are the solutions of the system
$$\left\{ 
\begin{array}{c}
y=\frac{5}{3}x-5 \\ 
y=-\frac{3}{5}x+\frac{13}{5},
\end{array}
\right. $$
which are $(x,y)=\left( \frac{57}{17},\frac{10}{17}\right) $.
A: It is the intersection of the line $\frac{x+4}{5}=\frac{y-5}{-3}$ and the line you gave.
A: Let $p_0$ be a point a the line, $v$ be a vector parallel to the line.
Then the orthogonal projection from $p$ to the line is $p_0$ + projection from $\vec{p_0p}$ to $v$.

Therefore a general solution is
$$p_0+\frac{(p-p_0)^Tv}{v^Tv}v$$
In you specific case, $v=[3,5]^T$, $p=[-4,5]^T$, choose $p_0=[0,-5]^T$. Hence,
$$
\newcommand\colv[1]{\begin{bmatrix}#1\end{bmatrix}}
\text{projection point} = 
\colv{0\\-5}
+\frac{\colv{-4&10} \colv{3\\5}}
{\colv{3&5} \colv{3\\5}}
\colv{3\\5}
=
\colv{0\\-5}+\frac{38}{34}\colv{3\\5}
=
\colv{\frac{57}{17}\\\frac{10}{17}}
$$
This solution does not involve matrix-vector multiplication and IMO is a better solution for who would like to implement in computer program.
For example, this python code can solve this question.
def vec_scale(v: tuple[float, float], a: float):
    return (a * v[0], a * v[1])


def vec_mul_add(v1: tuple[float, float], v2: tuple[float, float], a: float = 1):
    """calc v1+a*v2"""
    return (v1[0] + a * v2[0], v1[1] + a * v2[1])


def inner_prod(v1: tuple[float, float], v2: tuple[float, float]):
    """v1^T * v2"""
    return v1[0] * v2[0] + v1[1] * v2[1]


def solve(coef: tuple[float, float, float], p: tuple[float, float]):
    """
    Params:
      coef: 3-tuple (a,b,c) to represent the linear equation ax+by+c=0.
      p: 2-tuple (px,py) to represent the point.
    """
    a, b, c = coef
    # find p0 at the line
    if b == 0:
        p0 = (-c / a, 0)
    else:
        p0 = (0, -c / b)

    # find v
    if a == 0:
        v = (1, 0)
    elif b == 0:
        v = (0, 1)
    else:
        v = (b, -a)
    return vec_mul_add(
        p0, vec_scale(v, inner_prod(vec_mul_add(p, p0, -1), v) / inner_prod(v, v))
    )


print(solve((-5, 3, 15), (-4, 5)))
# output: (3.3529411764705883, 0.5882352941176467)

