Finding a perpendicular vector from a line to a point

7.6k Views Asked by At

Let's say I have an arbitrary linear line described by $y=mx+b$. I also have a point $P(x_1,y_1)$ that is not on that line. I suppose $P$ can be anywhere relative to the line. How can I find the vector $v$ the stretches from the point to the line (and is perpendicular to it)?

Here's what I tried: I figured that the difference in the $x$ and $y$ components ($\delta y$ and $\delta x$) basically describe a vector twice as large as $v$ but in the same direction. So I tried finding $\delta x$ and $\delta y$ by the following:

$\delta y=y_1-(m\cdot x_1 +b)$

$\delta x = x_1-(y_1/m - b/m)$

The vector V is then $[\delta x/2, \delta y/2]$. I divide by two because I figure the vector described by $[\delta x, \delta y]$ goes all the way to the top left corner of the imaginary rectangle that is completed by $\delta x$ and $\delta y$.

Am I correct? If not, why? Regardless if I am, is there an alternative or smarter way to accomplish this? I would appreciate any input here.

3

There are 3 best solutions below

2
On BEST ANSWER

First I will write the line $l$, defined by $y=mx+b$, as a parametric vector equation,

$$ l = \left\{\vec{u}_0 + \lambda \vec{u}_1, \lambda \in \mathbb{R}\right\}, \tag{1} $$

where $\vec{u}_0$ and $\vec{u}_1$ are equal to,

$$ \vec{u}_0 = \begin{pmatrix} 0 \\ b \end{pmatrix}, \tag{2} $$

$$ \vec{u}_1 = \begin{pmatrix} 1 \\ m \end{pmatrix}. \tag{3} $$

This notation will be useful when projecting an arbitrary point $P$ onto the line. Any point on $l$ can be seen as a scaled version of $\vec{u}_1$ with its origin at $\vec{u}_0$. The point $P$ can be seen as a vector with its origin at $\vec{0}$. Both origins have to be the same in order to be able to project $P$ onto the line. This can be done by adding $\vec{u}_0$ to its origin and subtracting $\vec{u}_0$ from $P$, which is visualized in the following figure:

                                          enter image description here

The projection of $P$ into $l$, denoted with $P'$ with its origin at $\vec{0}$, can be found with,

$$ P' = \frac{(P - \vec{u}_0) \cdot \vec{u}_1}{\vec{u}_1 \cdot \vec{u}_1} \vec{u}_1 + \vec{u}_0. \tag{4} $$

When writing $P$ as $(x_p,y_p)$ and using equation $(1)$ and $(2)$ for $\vec{u}_0$ and $\vec{u}_1$, then $P'$ can be simplified to,

$$ P' = \frac{(x_p + m (y_p - b)}{1 + m^2} \begin{pmatrix} 1 \\ m \end{pmatrix} + \begin{pmatrix} 0 \\ b \end{pmatrix}. \tag{5} $$

The vector $\vec{v}$, with its origin at $P'$ and point to $P$, can be found with,

$$ \vec{v} = P - P'. \tag{6} $$

5
On

Let $(x_2, y_2)$ be the foot of perpendicular drawn from the given point $P(x_1, y_1)$ to the line: $y=mx+b$ then the line joining $(x_1, y_1)$ & $(x_2, y_2)$ is perpendicular to the given line hence we have the following condition $$\text{slope of line joining}\ (x_1, y_1) \ \text{&}\ \ (x_2, y_2)=\frac{-1}{\text{slope of line:}\ y=mx+b}$$ $$\frac{y_2-y_1}{x_2-x_1}=\frac{-1}{m}\tag 1$$

Since, the foot of perpendicular $(x_2, y_2)$ is lying on the line: $y=mx+b$ hence, by satisfying the equation we have $$y_2=mx_2+b\tag 2$$ Now, solving (1) & (2), we can find out the coordinates $(x_2, y_2)$ as follows $$x_2=\frac{x_1+m(y_1-b)}{1+m^2},\ \ y_2=\frac{mx_1+m^2y_1+b}{1+m^2}$$

Hence, the vector $v$ from $P(x_1, y_1)$ to $(x_2, y_2)$ perpendicular to the line is determined as follows $$\overrightarrow v=i(x_2-x_1)+j(y_2-y_1)$$

0
On

Let the line $L$ be $$ax+by+c = 0 \tag{1}$$ Let P be $$ P = (x_1, y_1) \tag{2}$$ Now, to make calculations easier, shift the coordinate system by the vector given by the position $P$, so that $P$ is the origin of the new coordinate system and the new equation for $L$ is $$ a(x+x_1) + b(y+y_1) + c = 0 \tag{3}$$

If we let a the constant $s$ be the constant at the end of this equation, $$s = ax_1 + by_1+ c$$ The equation for $(3)$ becomes much shorter, $$ax + by + s = 0 \tag{4}$$

To calculate the vector that we need, which is from the line to $P$, we need to write the equation for the perpendicular line to the line $L$ and through the point $P$, which in the new coordinate system is given by $$ bx - ay = 0 \tag{5}$$ After a few manipulations we get $ bx = ay $ and $$x = \frac{a}{b} y$$ Now the intersection of $L$ and its perpendicular yields the other point of the vector. Substituting this into $(4)$ yields $a\frac{a}{b}y + by + s = 0$ then $(a^2 +b^2)y = -bs$, and finally $$y = \frac{-bs}{a^2 + b^2}$$ And similarly $x$ can be shown to be $$x = \frac{-as}{a^2 + b^2}$$

But since the vector begins at $(x,y)$ and goes to $P$, it's $$\begin{pmatrix} -x \\ -y \end{pmatrix}$$ So the vector may be written as $$\begin{pmatrix} a\\ b \end{pmatrix} \times \frac{ax_1 + by_1 + c}{a^2+b^2}$$ If the line is given as $y = mx +b$, we need only to rewrite it as $mx + b - y = 0$ and the new value is $$\begin{pmatrix} m\\ -1 \end{pmatrix} \times \frac{mx_1 + b -y_1}{m^2+1^2}$$.