43
$\begingroup$

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?

  • 2
    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.2012-07-27
  • 0
    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!2012-07-27
  • 0
    See formula 14 [here](http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html).2012-07-27
  • 0
    @enzotib: It is considered impolite in this site to remove or add "thank you" comments.2012-07-27
  • 1
    @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.2012-07-27
  • 0
    @Asaf: I didn't know that either. Is there a meta thread about this that I missed?2012-07-27
  • 0
    @Rahul: You can see that more than a handful of people expressed this opinion in various comments over meta threads. I cannot give you any recent event which is not a comment I wrote. However it feels that at least those participating the meta discussions tend to agree with that. If your Google search-fu is good you can probably find such comments on your own.2012-07-27

5 Answers 5

39

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

  • 0
    Thanks Theophile, absolutely ace method. I didn't even think about vectors!2012-07-27
  • 0
    Can you elaborate a little bit more on this solution or point me to a link so that I can understand it a little more? A program written would be awesome as well.2014-09-13
  • 0
    @Dewey Which part are you having trouble understanding?2014-09-14
  • 0
    How would you do Normalize this to u=v/||v||?2014-09-17
  • 4
    @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})$.2014-09-20
28

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.

Point on a line at a distance

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

  • 1
    Shouldn't `t = d / dt`?2016-04-21
  • 2
    @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.2016-08-09
  • 2
    @Marlon Thank you for confirming it.2016-08-09
  • 1
    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.2016-08-09
  • 0
    Multiplying x1 and y1 by t is clear but what is the logic behind multiplying x0 and y0 by (1-t) in (xt,yt)=(((1−t)x0+tx1),((1−t)y0+ty1)) ? Playing with the formula made it clear it was necessary but I wasn't able to intuit the logic behind it.2018-08-12
10

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

enter image description here

You can easily find D:

euclidean distance between Xa and Xb

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

enter image description here

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

enter image description here

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

enter image description here

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!!

  • 0
    thanks this was really helpful2018-11-29
2

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

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

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.

  • 0
    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](http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference). You may want to try using TeX by editing your answer (the link `edit` is under your post). Welcome to Math.SE!2013-01-01