I'm trying to check if a line hits a rectangle, and for that, I found this nice solution:
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.
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 \\ (y_1-y_2)\pmb{x}+(x_2-x_1)\pmb{y}-\left((y_1-y_2)x_1+(x_2-x_1)y_1\right)&=0 \\ (y_1-y_2)\pmb{x}+(x_2-x_1)\pmb{y}+\left(-(y_1-y_2)x_1-(x_2-x_1)y_1\right)&=0 \\ (y_1-y_2)\pmb{x}+(x_2-x_1)\pmb{y}+\left((y_2-y_1)x_1-(x_2-x_1)y_1\right)&=0 \end{align}$$