# How to get the second point in a line segment knowing its first point, distance and perpendicular line segment?

I need to get the second point in a line segment knowing its first point, distance and perpendicular line segment. The line segments need to intersect , thus the direction of the incomplete line segment could differ based on the location of its first point. The problem I have now is that I don't know how to obtain the direction of the incomplete line segment.

This is what is known:

a1 = (30, 30)

a2 = (10, 30)

b1 = (30, 35)

d = 30 (distance of line segment b)

I tried the following:

Get perpendicular slope a.

m = (b2.x - b1.x) / (b2.y - b1.y);


Get horizontal direction.

hd = ?  // either 1 or -1


Get a2.

a2.x = a1.x + d * cos(atan(m)) * hd;
a2.y = a1.y + d * sin(atan(m));


I am missing the step to get the horizontal direction of the slope of b, I was unable to recognize the pattern. Or perhaps there is a better and shorter algorithm to figure out point b2?

• There are two possibilities for $B_2$. The drawing suggests that you’re to choose the one for which $\overrightarrow{B_1B_2}$ is rotated counterclockwise from $\overrightarrow{A_1A_2}$. Is that the case? – amd Nov 26 '16 at 6:41
• @amd the drawing represents the wanted outcome. I will edit the question to make clear that the line segments need to intersect. – oddRaven Nov 26 '16 at 9:40

• $$\vec{A_1A_2}•\vec{B_1B_2}=0$$
• $$||\vec{B_1B_2}||^2=900$$
Observe that $A_1A_2$ is a segment parallel to X-Axis. And also that $B_1$ is a point directly above $A_1$. So, the diagram looks like this : It's trivial to figure out the coordinates of $B_2$ now.