How to obtain equation of line of the form $ax + by + c = 0$?

I’m trying to check if a line hits a rectangle, and for that, I found this nice solution:

Line triangle intersection

The problem is that, having forgot almost all I ever knew about math, I don’t know how to obtain that equation of a line which they use there: $4x − 3y + 2 = 0$

I know a line’s equation is $y = mx + b$. But the above form and how can I obtain it is a mystery to me. Can somebody please bring a flashlight? ::- D.

Solutions Collecting From Web of "How to obtain equation of line of the form $ax + by + c = 0$?"

If you know two points on the line, $(x_1,y_1)$ and $(x_2,y_2)$, then the vector $\langle x_2-x_1,y_2-y_1\rangle$ is in the direction of the line and the vector $\vec{n}=\langle y_1-y_2, x_2-x_1\rangle$ (swap the components, take the opposite of one component) is orthogonal (perpendicular) to the line. For any point $(\pmb{x},\pmb{y})$ on the line, the vector $\langle \pmb{x}-x_1,\pmb{y}-y_1\rangle=\langle \pmb{x},\pmb{y}\rangle-\langle x_1,y_1\rangle$ is in the direction of the line, so it is also orthogonal to $\vec{n}$, so its dot product with $\vec{n}$ is $0$: $$\begin{align}
\vec{n}\cdot\langle \pmb{x}-x_1,\pmb{y}-y_2\rangle&=0
\vec{n}\cdot\left(\langle \pmb{x},\pmb{y}\rangle-\langle x_1,y_1\rangle\right)&=0
\vec{n}\cdot\langle \pmb{x},\pmb{y}\rangle-\vec{n}\cdot\langle x_1,y_1\rangle&=0
\langle y_1-y_2, x_2-x_1\rangle\cdot\langle \pmb{x},\pmb{y}\rangle-\langle y_1-y_2, x_2-x_1\rangle\cdot\langle x_1,y_1\rangle&=0

You can transform the given equation to make it explicit in $y$ to obtain the form that you are familiar with:
4x – 3y + 2 =& 0 \\
4 x + 2 =& 3y \\
\frac{4}{3}x + \frac{2}{3} =& y \\
y =& \frac{4}{3}x + \frac{2}{3}

From this you can tell that the line crosses the $y$-axis at $\frac{2}{3}$ and that the slope of the line is $\frac{4}{3}$: when $x$ increases by 1, $y$ increases by $\frac{4}{3}$.

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} $$

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)$