Borrowing from Homogeneous coordinates I set $A=y_2-y_1$, $B=x_1-x_2$ and $C=x_2 y_1-x_1 y_2$ such that $[A,B,C]\cdot[x,y,1]=A x + B y + C = 0$ is the equation of the line.
The distance of a vertex $P=(x_P, y_P)$ from the line is $ d = \frac{A x_P+B y_P + C}{\sqrt{A^2+B^2}} $
and the closest point $Q$ on the line from point $P$ lies in $ \begin{bmatrix} x_Q \\ y_Q \end{bmatrix} = \frac{1}{A^2+B^2} \begin{bmatrix} B^2 \,x_P - A B \;y_P \\ A^2 \,y_P - A B \;x_P \end{bmatrix} $
Edit: Homogeneous coordinates (HC) are a way to represent points, planes and lines for computer graphics methods. A point $(x,y)$ is represented by three coordinates $[x,y,1]$ and every scalar multiple of it, such as $[2x,2y,2]$. To get the point back from the 3 coordinates $[a,b,c]$ divide by the last value $(x,y)=(a/c,b/c)$.
The equation of the line through two points is derived from the line coordinates $ L = [y_2-y_1, x_1-x_2, x_2 y_1-x_1 y_2] $ in a way that when the dot-product with a point is zero that point falls on the line. So any point with coordinates $[x,y,1]$ that lies on the line has $ [x,y,1]\cdot[y_2-y_1, x_1-x_2, x_2 y_1-x_1 y_2]=0 $ $ x(y_2-y_1)-y(x_2-x_1)+( x_2 y_1-x_1 y_2)=0 $ which is the equation of the line in $Ax+By+C=0$ form. As a function the line is $y =-(A/B) x-(C/B)$