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



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

| cite | improve this answer | |
  • $\begingroup$ Thanks for the reply! I know how to solve this with vectors. However is there a mathematical formula to find the point ? $\endgroup$ – user2741186 Dec 5 '16 at 17:41
  • $\begingroup$ Go through the same exercise but don't substitute in the numbers. $\endgroup$ – John Dec 5 '16 at 17:49
  • $\begingroup$ Yeah but I can't use vectors here. So basically I need a formula that takes x1, x2, y1, y2 and d; gives me x3 y3. $\endgroup$ – user2741186 Dec 5 '16 at 18:08
  • $\begingroup$ Edited my answer. $\endgroup$ – John Dec 5 '16 at 18:30
  • $\begingroup$ That was exactly what I needed. Works like a charm. Thanks! $\endgroup$ – user2741186 Dec 5 '16 at 18:54

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

| cite | improve this answer | |

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

| cite | improve this answer | |

If you are a software developer, you like this

def get_point_between_points(p1, p2, distance):

    dist_btw_points = np.sqrt((p2.x - p1.x) ** 2 + (p2.y - p1.y) ** 2)

    distance_ratio = distance / dist_btw_points
    x = p1.x + distance_ratio * (p2.x - p1.x)
    y = p1.y + distance_ratio * (p2.y - p1.y)

    return [x, y]


  1. Get the ratio of distance with respect to two points total distance.
  2. Multiply with the difference and add it with point 1.
| cite | improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.