Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
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. –  Rahul Jul 27 '12 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! –  Kel196 Jul 27 '12 at 15:34
    
See formula 14 here. –  J. M. Jul 27 '12 at 15:49
    
@enzotib: It is considered impolite in this site to remove or add "thank you" comments. –  Asaf Karagila Jul 27 '12 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. –  enzotib Jul 27 '12 at 18:57
show 2 more comments

2 Answers

up vote 4 down vote accepted

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

share|improve this answer
    
Thanks Theophile, absolutely ace method. I didn't even think about vectors! –  Kel196 Jul 27 '12 at 16:03
add comment

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.

share|improve this answer
    
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 '13 at 5:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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