[Math] Given a point, slope and a distance along that slope, easily (?) find a second point.

geometry

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.

Best Answer

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