12

Lets say I have point P1(10,10) and P2(20,20).

I want to find a P3 which is on between this two points and 3 units away from P1.

What is the formula to find P3 ?

Known values: X1, X2, Y1 , Y2, distance.

Wanted values: X3, Y3

https://i.stack.imgur.com/wprMd.png

turkeyhundt
  • 7,733

3 Answers3

14

Here are some hints:

  1. Find the unit vector that points from P1 to P2.
  2. Multiply that vector by $3$ and add it to P1.

In general terms, the unit vector is

$$\hat{u} = \frac{x_2-x_1}{D}\hat{x} + \frac{y_2-y_1}{D}\hat{y},$$

where $\hat{x}, \hat{y}$ are unit vectors in the $x$ and $y$ directions, and $D = \sqrt{(x_2-x_1)^2+(y_2-y_1)^2}$ is the distance between $P_1$ and $P_2$.

Then, if you're looking for the point a distance $d$ away from $P_1$ along the line through $P_1$ and $P_2$, then, vector-based the answer is

$$\vec{P_3} = \vec{P_1} + d\hat{u}.$$

Splitting up the components gives:

$$x_3 = x_1 + \frac{d}{D}(x_2-x_1)$$

$$y_3 = y_1 + \frac{d}{D}(y_2-y_1).$$

John
  • 26,319
2

A point on the line through $P_1$ and $P_2$ will have the form $$\mathbf x = (1-\lambda)P_1 + \lambda P_2$$ for some $\lambda \in \mathbb R$. If $\lambda \in [0,1]$, then $\mathbf x$ will be on the line segment between $P_1$ and $P_2$. In particular, when $\lambda = 1$, then $\mathbf x = P_2$.

Let's scale $\lambda$ to $\lambda'$ so that $\mathbf x = P_2$ when $\lambda' = 10\sqrt2$, which is the distance from $P_1$ to $P_2$. In other words, we have $\lambda' = 10\sqrt2\lambda$, so $$\mathbf x = \left(1-\frac{\lambda'}{10\sqrt2}\right)P_1 + \frac{\lambda'}{10\sqrt2}P_2.$$

Now substitute $\lambda' = 3$.

Théophile
  • 24,627
0

There is a formula, but you'll have to modify it to suit your needs. The distance formula says that the distance between A(x1,y1) and B(x2,y2) is $\sqrt {(x_2-x_1)^2+(y_2-y_1)^2}$

But here, since x1=y1 and x2=y2, it becomes $\sqrt {2(x_2-x_1)^2}$

This is $10\sqrt2$

So, the distance between A(10,10) and B(20,20) is $10\sqrt2$

So your point C, which is 3 units away from A, divides the line segment AB into two parts, 3 and $(10\sqrt2-3)$

Another formula says that if a point C(x,y) divides a line between 2 points A(x1,y1) and B(x2,y2) in the parts (ratio actually, but since here the parts are coprime, it is equivalent) m and n, its coordinates are $${mx_2+nx_1\over{m+n}},{my_2+ny_1\over{m+n}}$$

Substituting values, we get the point to be $$C\left({20-{3\over\sqrt2}},{10+{3\over\sqrt2}}\right)$$

DynamoBlaze
  • 2,781