I want to understand the formula for using a slope and distance from a point either a positive or negative direction: to: determine the X coordinate of a point on that line which is "D" distance away from your original point in the direction which you specified.

I found this link: " https://www.freemathhelp.com/forum/threads/70424-Find-coordinates-given-original-point-and-slope " which has an equation which supposedly does what I want; but could someone please explain the formula I need, to me in plain enlgish, and also in the standard formula form (like the kind most people use), and also in psuedo-code?

So that I may tripple-check my comprehension?

I can get anxiety and then second-guess myself on these matters; so I get next-to-nothing done sometimes...

bonus point if you can explain to me a procedure for writing the program in N-dimensional coordinate space; but if you would rather not: I only desperately need 2-dimensional (x,y) coordinate space right now...


3 Answers 3


Consider the equation of your line $y=m(x-a)+b$ and the equation of a circle with radius $D$ from your original point, $D^2=(x-a)^2+(y-b)^2$. Here I am assuming the coordniates of your original point is $(a,b)$. Because the point of intersection between the circle and line have to have the same x and y coordinate you can then substitute the $y$ from your line into the circle to give you $D^2=(x-a)^2+(m(x-a))^2$. From there you can solve for $x$. If you need more guidance from there I can give you some more hints.

  • $\begingroup$ Where does the op mention any circles, or intersection of thereof? $\endgroup$ Feb 1, 2018 at 21:50
  • $\begingroup$ The op mentions distances. A circle is all points equidistance for a center. So the points on the line that are that distance away, will be points on the circle. So the points will be the points of intersection of the line and the circle. The OP didn't mention circles. But this answer did. Because they solve the problem. $\endgroup$
    – fleablood
    Feb 1, 2018 at 21:57
  • $\begingroup$ Why is "D" squared? Your answer seems like the simplest/easiest/best; but I'm missing something, and hence fail to grasp it, please explain (sorry for my lack of competence) $\endgroup$
    – user179283
    Feb 2, 2018 at 1:22
  • $\begingroup$ Its fine! $D^2$ represents the square of the distance from your original point. There is nothing to be worry about, I'm here to try and answer your questions. $\endgroup$ Feb 2, 2018 at 1:42
  • $\begingroup$ Actually, like this one better than mine. It's a simple formula. I reinvented the wheel and hammered through. $\endgroup$
    – fleablood
    Feb 2, 2018 at 1:48

You have a point with coordinates $(w,z)$.

Part I:

Suppose there were another point on the plane. Any point on the plane. We aren't worry about how to get the point you want; just any point with coordinate $(a,b)$.

So what is the distance between $(w,z)$ and $(a,b)$? Well, in the horizontal direction $w$ and $a$ are $|w - a|$ apart. In the vertical direction $b$ and $z$ are $|z-b|$ apart. The vertical and the horizontal distances form two legs of a right triangle. The hypotenuse of that triangle will be the distance between the points.

The pythagorian theorems says this hypotenuse squared is the sum of the squares of the legs. So $distance^2 = |w-a|^2 + |z-b|^2$ and so $distance = \sqrt {(w-a)^2 + (z-b)^2}$.

This is the famous distance formula. $d((x_0,y_0) =$ distance between point $(x_0, y_0)$ and $(x_1,y_1)$ $= \sqrt {(x_1-x_0)^2 + (y_1-y_0)^2}$.

Put a pin in that.


Part II

You have a slope that is $m$. That means if you move $k$ units in the horizontal direction you will move $km$ units in the vertical direction. This work forward and backwards. If you move $-k$ units in the horizontal direction you will move $-km$ units in the vertical direct.

So if you move $k$ units forward from point $(w,z)$ your $x$- coordinate will be $w + k$, and your $y$- coordinate will be $y +km$ or the point $(w + k, z + km)$.

We can use this do find an equation for the line. A point of the line will be any point $(x,y)$ where $x = w +k$ and $y = z + km$. Manipulating this algebraically we get $k = x-w$ so $y=z +(x-w)m = mx + (z-wm)$. (Note: $z-wm = b$ equals the $y$ intercept because we had to go $w$ units back to get to $x=0$ and that means vertically we needed to go back $mw$ units.)


Part III

So we have a point $(w,z)$ and the line. We want to move it forward (or back) $k$ units to get the point $(w + k, z + km)$ and we want $d((w,z), (w+k,z+km)) = $ to a specific distance $D$.

So we want $d((w+k, z+km)) = \sqrt{[(w+k)-w]^2 + [(z+km) - z)]^2} = D$.

Well.... let's do it. Let's solve for $k$ (which is how for we must move forward horizontally).

$\sqrt{[(w+k)-w]^2 + [(z+km) - z)]^2} = D$

$\sqrt {k^2 + (km)^2 } = D$

$k^2 + k^2m^2 = D^2$

$k^2(1 + m^2) = D^2$

$k^2= \frac {D^2}{1+m^2}$

$k = \frac {D}{\sqrt{1+m^2}}$.

So the point we want is that we go $\frac {D}{\sqrt{1+m^2}}$ horizontally, and $m*\frac {D}{\sqrt{1+m^2}}$ vertically.

So the point is $(w + \frac {D}{\sqrt{1+m^2}}, z + m\frac {D}{\sqrt{1+m^2}})$.

To go in the opposite direct you get $(w - \frac {D}{\sqrt{1+m^2}}, z - m\frac {D}{\sqrt{1+m^2}})$

So $(w \pm \frac {D}{\sqrt{1+m^2}}, z \pm m\frac {D}{\sqrt{1+m^2}})$



Suppose you have a point $(8, 9)$ and we have a slope of $\frac 34$ and we want to find the two points that are $5$ units away.

Our formula is $(x \pm \frac {D}{\sqrt{1+m^2}}, y \pm m\frac {D}{\sqrt{1+m^2}})$

So $(8\pm \frac 5{\sqrt{1+ \frac 9{16}}}, 9\pm \frac 34\frac 5{1 + \frac 9{16}}) = $

$(8\pm \frac 5{\sqrt{\frac {25}{16}}}, 9\pm \frac 34\frac 5{\sqrt{\frac {25}{16}}})=$

$(8 \pm \frac 5{\frac 54}, 9\pm \frac 34*\frac 5{\frac 54})=$

$(8\pm 4, 9\pm 3)$

so the points are $(4, 6)$ and $(12, 12)$. So $(

  • $\begingroup$ This answer was very helpful, and seems to be exactly what I wanted; I'm feeling a bit mentally fatigued today, so I only skimmed it, but I get the feeling that: once I sit down and play with it a bit; I'll understand better, seems very complete and good $\endgroup$
    – user179283
    Feb 2, 2018 at 1:13

So so you have a point

$$ \mathbf{p} = \pmatrix{a\\b} $$

and a direction, given a slope $m$, the direction angle $\theta$, or another point $\mathbf{q} = \pmatrix{c \\ d}$.

The direction vector is

$$ \mathbf{e} = \pmatrix{e_x \\e_y} = \pmatrix{1 \\ m} = \pmatrix{ \cos\theta \\ \sin\theta} = \pmatrix{c-a \\ d-b} $$

This just describes how much you move up or down $e_y$ for every move to the right $e_x$.

Now you have an equation for any point along the line with a distance $t$ from $\mathbf{p}$

$$ \mathbf{r} = \mathbf{p} + t \, \frac{\mathbf{e}}{\| \mathbf{e} \|} $$

$$ \pmatrix{x\\y} = \pmatrix{a\\b} + \frac{t}{\sqrt{e_x^2+e_y^2}} \pmatrix{e_x\\e_y} $$

where $\| \mathbf{e} \| = \| \pmatrix{e_x & e_y} \| = \sqrt{e_x^2+e_y^2}$ is the length of the direction vector.

The explanation is that the length of the direction vector $\| \mathbf{e} \|$ represents physical distance the vector spans. Since you want this distance to be 1 when $t=1$ the vector is scaled to form a unit vector (vector with length equal one)

$$\mbox{(unit vector)} = \frac{1}{\| \mathbf{e} \|} \mathbf{e} = \frac{1}{\sqrt{e_x^2+e_y^2}} \pmatrix{e_x\\e_y} = \pmatrix{\frac{e_x}{\sqrt{e_x^2+e_y^2}}\\\frac{e_y}{\sqrt{e_x^2+e_y^2}}}$$

In arbitrary dimensions, the equation is still

$$ \mathbf{r} = \mathbf{p} + t \, \frac{\mathbf{e}}{\| \mathbf{e} \|} $$

with an appropriate calculation of the length $\| \mathbf{e} \| = \sqrt{ e_x^2+e_y^2+e_z^2+ \ldots} $.

  • $\begingroup$ Interesting... your answer is very satisfying as well, but for personal reasons I try to shy away from irrational trig functions (with the exception of square root) because I am trying to create a version of angles which does without them; as a matter of personal pride. Literally anyone else in the world would pick your answer though; and I do find it to be very comprehensive. If I could checkmark more than one answer: yours would be one of my chosen answers; thank you $\endgroup$
    – user179283
    Feb 2, 2018 at 1:20

Not the answer you're looking for? Browse other questions tagged .