13
$\begingroup$

I have a point [x1,y1], a slope m of a line that passes through that point. I'd like to find either point [x,y] that is d distance away from that original point.

Work so far:

$$ y = m(x - x_1) + y_1 $$ $$ x = \frac{y + mx_1 - y_1}m $$

And then (if my algebra is correct)

$$ d = \sqrt{ \left(\frac{y + mx_1 - y_1} m\right)^2 +y^2} $$ $$ y^2 = d^2 - \left(\frac{y + mx_1 - y_1}{m}\right)\left(\frac{y + mx_1 - y_1}{m}\right) $$ And then, if I plugged in some real numbers and struggled long enough, I suppose I could solve for y. And then solve for x. My first attempt ended in a few pages of poorly-remembered math and an incorrect answer.

My question is that this seems like a long slog. Is there an easier way?

More details: The general problem I'm trying to solve for a computer program is given a line segment find a point that is perpendicular and a fixed distance away from the mid-point.

$\endgroup$
1
  • 2
    $\begingroup$ Using the $x$ perspective instead of the $y$ perspective would allow for less division involved... $$d^2=(m(x-x_1)+y_1)^2+x^2$$ $\endgroup$
    – abiessu
    Jan 29, 2014 at 21:28

3 Answers 3

13
$\begingroup$

You can get rid of lots of algebra with a little trigonometry. $m=\tan \theta$, the angle between the $x$ axis and the line. Then $x-x_1=d \cos \theta = d \cos( \arctan (m))=d\frac 1{\sqrt {1+m^2}}$ Similarly $y-y_1=d \sin (\arctan(m))=d\frac m{\sqrt{1+m^2}}$

$\endgroup$
3
  • $\begingroup$ Thank you for this. My first attempt was with trig, but it turns out I was even more rusty in my trig that in my geometry. $\endgroup$
    – GSP
    Jan 30, 2014 at 14:27
  • $\begingroup$ Can you please explain. How to use it in programming language. I know (x1,y1) , slope m and distance need to find the (x2,y2). Help please. $\endgroup$
    – Sabish.M
    Apr 22, 2018 at 15:22
  • $\begingroup$ I give you equations for $x,y$. Those are your $x_2,y_2$ $\endgroup$ Apr 22, 2018 at 16:31
11
$\begingroup$

Nicer solution: you know that the vector $(1, m)$ points in the direction of your line. Divide by $r= \sqrt{1 + m^2}$ to get a unit-length vector $(1/r, m/r)$ that points along the line. Now add $d$ times that vector to $(x, y)$: $$ r = \sqrt{1 + m^2}\\ (x_1, y_1) = (x + \frac{d}{r}, y + \frac{d\cdot m}{r}) $$

$\endgroup$
1
  • 5
    $\begingroup$ Perhaps the new point is actually $$(x_1, y_1) = (x + \frac{d}{r}, y + \frac{d\cdot m}{r})$$ given the multiplication of $\frac dr$ times the vector $(1,m)$... $\endgroup$
    – abiessu
    Jan 29, 2014 at 21:38
4
$\begingroup$

It might be simpler to work with vectors, here. You can rewrite as a vector equation $$\langle x,y\rangle = \langle x_1,y_1\rangle +t\langle 1,m\rangle,\tag{$\star$}$$ where $t$ is allowed to vary over all real numbers. Then the distance from $\langle x_1,y_1\rangle$ to a point $\langle x,y\rangle$ on the line is precisely the magnitude of the vector $$\langle x,y\rangle-\langle x_1,y_1\rangle=t\langle 1,m\rangle=\langle t,mt\rangle.$$ Hence, we need $$d=\sqrt{t^2+(mt)^2}=\sqrt{t^2(1+m^2)}=|t|\sqrt{1+m^2},$$ and so we need $$t=\pm\frac{d}{\sqrt{1+m^2}}.$$ Substituting these values of $t$ into $(\star),$ we find that the solutions are $$\left\langle x_1\pm\frac{d}{\sqrt{1+m^2}},y_1\pm\frac{dm}{\sqrt{1+m^2}}\right\rangle.$$

Added: Obviously, this doesn't work with vertical lines, but that's even easier, since only the $y$-value is changing.

$\endgroup$

You must log in to answer this question.

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