Home > front end >  how to find the coordinates of the intersection point of a line ( parallel to a given line) and othe
how to find the coordinates of the intersection point of a line ( parallel to a given line) and othe

Time:04-19

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. 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