how to find the coordinates of the intersection point of a line ( parallel to a given line) and other line

Viewed 185

I have 3 point A, B, C in the link. The points generate a triangle ABC.2 red lines parallel to AB and distance between them is 30. the green line passes through B and is perpendicular to AC. here is picture to describe it

How can I find the coordinate between 2 red lines and the green line

solution

Thank you @MBo, and I want to provide an easier way to understand in the last expression: I will put the ip1 coordinate as

ip1 = b.x + t * n.x, b.y + t * n.y                                     (1)

So the distance between ip1 and b will be:

d / sine(n, BA) = sqrt ((t * n.x) ** 2 + (t * n.y) ** 2)

You can calculate t easily and after that put it in the (1) to find ip1 and ip2 as well

1 Answers

Assuming you want two intersection points between height Bh and red lines (parallel to BA at distance d):

enter image description here

Get vectors

AC = C.x - A.x, C.y- A.y
BA = A.x - B.x, A.y- B.y

and normalize them ((make unit length dividing components by vector magnitude)

Get height vector as perpendicular to AC as

n = -ac.y, ac.x

Find sine of angle between n and BA using cross product

s = abs(n.x * ba.y - n.y * ba.x)

Now get coordinates of intersection points:

ip1 = B + n * d / s
ip2 = B - n * d / s

That's all.

Related