How to find out (x2, y2) when I know the equation of a function, (x1, y1) and the distance between the two points?

900 Views Asked by At

I'm writing a program in which I have to draw something along a line multiple time and spaced evenly. I used two points [$(x_1,y_1)$ and $(x_3, y_3)$] to create a line. Then I found out the equation $y = mx+b$ of the line going through those two points. Now I want to draw multiple time between those two points with a distance $d$ between each drawing [first drawing is at $(x_1, y_1)$].

I know the squared distance between two points in a coordinate system is $d^2 = (x_1 - x_2)^2 + (y_1 -y_2)^2$. But I am not sure how to figure out $x_2$ and $y_2$ from there. is it even possible? is there another way to know $x_2$ and $y_2$ with all the other known information?

2

There are 2 best solutions below

0
On

$(x_2-x_1)^2+(y_2-y_1)^2=d^2$ is in fact the equation of a circle with radius $d$ and center on $(x_1, y_1)$, so to find $x_2$ and $y_2$ you have to find the intersection of line $y=mx+b$ with this circle , that is you have to solve following system of equation:

$\begin{cases}(x-x_1)^2+(y-y_1)^2=d^2\\ y=mx+b\end{cases}$

You have $x_1$, $y_1$ and $d$ so you can find x and y which in fact is $x_2$ and $y_2$

0
On

I think the easiest way is to write the line in vector form where $\vec{n} = \frac 1{\sqrt{1+m^2}}\begin{pmatrix}1 \\ m\end{pmatrix}$ is the normalized direction vector. You will find the $k$-th point on the line starting from $\begin{pmatrix}x_1 \\ y_1\end{pmatrix}$ by

$$\begin{pmatrix}x \\ y\end{pmatrix}= \begin{pmatrix}x_1 \\ y_1\end{pmatrix}+k\cdot d\cdot \vec{n} = \begin{pmatrix}x_1 \\ y_1\end{pmatrix}+k\frac{d}{\sqrt{1+m^2}}\begin{pmatrix}1 \\ m\end{pmatrix}$$

Here is a Desmos-graph which illustrates above formula. You may start with a horizontal line to see that the distance fits and then change the slope $m$ and animate $k$.