# Finding a point along a line a certain distance away from another point!

Let's say you have two points, $(x_0, y_0)$ and $(x_1, y_1)$.

The gradient of the line between them is:

$$m = (y_1 - y_0)/(x_1 - x_0)$$

And therefore the equation of the line between them is:

$$y = m (x - x_0) + y_0$$

Now, since I want another point along this line, but a distance $d$ away from $(x_0, y_0)$, I will get an equation of a circle with radius $d$ with a center $(x_0, y_0)$ then find the point of intersection between the circle equation and the line equation.

Circle Equation w/ radius $d$:

$$(x - x_0)^2 + (y - y_0)^2 = d^2$$

Now, if I replace $y$ in the circle equation with $m(x - x_0) + y_0$ I get:

$$(x - x_0)^2 + m^2(x - x_0)^2 = d^2$$

I factor is out and simplify it and I get:

$$x = x_0 \pm d/ \sqrt{1 + m^2}$$

However, upon testing this equation out it seems that it does not work! Is there an obvious error that I have made in my theoretical side or have I just been fluffing up my calculations?

• Looks about right to me. In particular, it gives the right result for reasonable values of $m = 0$, $m = 1$, $m = \infty$. Maybe there is a bug in your implementation.
– user856
Jul 27, 2012 at 15:28
• Thanks for the quick reply Rahul, i've been trying to programme this and you are right! it was an error in my implementation. Thank you for taking the time to read my question! Jul 27, 2012 at 15:34
• See formula 14 here. Jul 27, 2012 at 15:49
• @enzotib: It is considered impolite in this site to remove or add "thank you" comments. Jul 27, 2012 at 18:55
• @AsafKaragila: sorry, I didn't know, in other SE sites it is considered superfluous to have such comments. I will take it into account for the future. Jul 27, 2012 at 18:57

Another way, using vectors:

Let $\mathbf v = (x_1,y_1)-(x_0,y_0)$. Normalize this to $\mathbf u = \frac{\mathbf v}{||\mathbf v||}$.

The point along your line at a distance $d$ from $(x_0,y_0)$ is then $(x_0,y_0)+d\mathbf u$, if you want it in the direction of $(x_1,y_1)$, or $(x_0,y_0)-d\mathbf u$, if you want it in the opposite direction. One advantage of doing the calculation this way is that you won't run into a problem with division by zero in the case that $x_0 = x_1$.

• Thanks Theophile, absolutely ace method. I didn't even think about vectors! Jul 27, 2012 at 16:03
• @Dewey Which part are you having trouble understanding? Sep 14, 2014 at 13:07
• @Dewey The length of a vector $\mathbf v = (v_1,v_2)$ is defined as $||\mathbf v|| = \sqrt{v_1^2 + v_2^2}$. The vector $\mathbf v \over ||\mathbf v||$, that is, $\Big(\dfrac{v_1}{\sqrt{v_1^2 + v_2^2}}, \dfrac{v_2}{\sqrt{v_1^2 + v_2^2}}\Big)$, points in the same direction as $\mathbf v$ and has unit length. For example, if $\mathbf v = (3,4)$, then $\mathbf u = ({3 \over 5}, {4 \over 5})$. Sep 20, 2014 at 23:00
• @jpwrunyan Which notation are you having difficulty with? May 30, 2019 at 16:57
• @jpwrunyan Ah, I see! Okay, first, $||\bf v||$ refers to the length of the vector $\bf v$, which you can calculate using Pythagoras's theorem. In other words, if ${\bf v}=(x,y)$, then its length is $\sqrt{x^2+y^2}$. Next, about $v_1^2$ and $v_2^2$: these are easier than you think! They're just a compact way of writing $(v_1)^2$ and $(v_2)^2$, so in fact they aren't related to matrix notation (although that was a good guess). So if ${\bf v}=(x,y)$, then $||{\bf v}||=\sqrt{x^2+y^2}$; this is exactly the same as my previous comment but with differently named variables. Does that make more sense? May 31, 2019 at 21:48

Let me explain the answer in a simple way.

Start point - $(x_0, y_0)$

End point - $(x_1, y_1)$

We need to find a point $(x_t, y_t)$ at a distance $d_t$ from start point towards end point.

The distance between Start and End point is given by $d = \sqrt{(x_1-x_0)^2+(y_1-y_0)^2}$

Let the ratio of distances, $t=d_t/d$

Then the point $(x_t, y_t) =(((1-t)x_0+tx_1), ((1-t)y_0+ty_1))$

When $0<t<1$, the point is on the line.

When $t<0$, the point is outside the line near to $(x_0,y_0)$.

When $t>1$, the point is outside the line near to $(x_1,y_1)$.

• Shouldn't t = d / dt? Apr 21, 2016 at 1:54
• @skibulk nope it's t = dt / t when I applied this to my code I followed your comment. But something was bugging out, turns out t = dt / t is correct. Aug 9, 2016 at 9:40
• @Marlon Thank you for confirming it. Aug 9, 2016 at 15:00
• Oh yes, you're correct. For some reason it I was thinking dt was "distance total" of the segment, which is be the divisor. Bit I guess it's supposed to be "distance time". Anyway, it's correct according to the illustration. Aug 9, 2016 at 16:17
• If you only want to extend the line by a percentage, you don't need to calculate the distance, where p is a decimal percentage: dt = d * p, t = (d * p) / d, thus t = p
– Kyle
Apr 11, 2019 at 17:23

You can very easily find it with trigonometry!!

Let's say Xa and Xb are the two points of your line, and D is the distance between them. And you are looking to find Xc which is D2 away from Xa (as the diagram bellow):

You can easily find D:

The formulas that you can find Xa, Xb, Xc, D and D2 are:

But SINa-b and SINa-c share the same the same corner, so they are equal:

Since you know the distance (D2) between Xa and Xc that you are looking for, you can easily solve the following:

In conclusion by solving the formula for D and the last one you are done. (You need one for the Y as well, just replace in the last one, X with Y )

Hope it helps!!

• thanks this was really helpful Nov 29, 2018 at 4:39
• sweet solution! Jul 17, 2019 at 19:41
• what tool did you use to draw the sketch? Sep 15, 2021 at 4:12
• @ddzzbbwwmm I think it was inkscape. A good online alternative is: draw.io Sep 16, 2021 at 6:27
• @Pontios Geogebra would be an interesting online alternative. geogebra.org/classic?lang=en Mar 16 at 14:30

The easy way in rectangular coordinate systems is to use the vector formula
P = d(B - A) + A
where
A is the starting point (x0, y0) of the line segment
B is the end point (x1, y1)
d is the distance from starting point A to the desired collinear point
P is the desired collinear point

• I have compared and tested this solution with the answer from @SenJacob above and this is NOT correct. Jul 13, 2017 at 13:21
• This is the same as Théophile's answer, but it omits to mention that you need to normalize (B-A) Jul 17, 2017 at 1:40

I think you need to check $x_0 > x_1$ when you try to calculate $x$ (last equation in your calculation) then you determine it will be $(+)$ or $(-)$ in your equation.

• Thank you for your contribution. This site supports basic TeX syntax, which allows formulas to be nicely typeset as $x_0>x_1$, for example. There is a short TeX tutorial. You may want to try using TeX by editing your answer (the link edit is under your post). Welcome to Math.SE!
– user53153
Jan 1, 2013 at 5:47

There is an other way to solve this problem.

The function $$\rho:\mathbb R \to \mathbb R^2$$ defined by

$$\rho(t) = (1-t)(x_0,y_0) + t(x_1,y_1)$$

describes the line through the points $$(x_0,y_0)$$ and $$(x_1,y_1)$$ with $$\rho(0) = (x_0, y_0)$$ and $$\rho(1)=(x_1,y_1)$$. If you let $$D = \sqrt{(x_1-x_0)^2 + (y_1-y_0)^2},$$ then it is fairly easy to show that

$$|\rho(t) - \rho(s)| = D|t-s|$$

So, if you want to find the points a distance of $$d$$ from $$(x_0,y_0)$$, then you need to solve $$d = |\rho(t) - \rho(0)| = D|t-0|$$

You get $$t = \pm \dfrac dD$$. Hence the points are

$$\rho\left( \pm \dfrac dD \right) = \left\{ \begin{array}{c} \left( 1-\dfrac dD \right)(x_0,y_0) + \dfrac dD (x_1,y_1) \\ \left( 1+\dfrac dD \right)(x_0,y_0) - \dfrac dD (x_1,y_1) \end{array} \right.$$