Point of Intersection between Two LinesDate: 07/08/2003 at 09:28:24 From: Mr. Pintu Saha Subject: Getting point of intersection between two lines Sir, I am developing a software program (civil work) and am facing a problem. I have one line whose coordinates are (x1,y1) and (x2,y2). There is another line with coordinates (x3,y3) and (x4,y4). The problem is how to check if these lines intersect between these coordinates, and if yes, find the point of intersection (x,y) I am doing the software in VB. Date: 07/08/2003 at 13:23:43 From: Doctor George Subject: Re: Getting point of intersection between two lines Hi Pintu, Thanks for writing to Doctor Math. Let L12 and L34 be the lines through the two pairs of points, and call each point Pi = (xi,yi). We can write vector equations for the two lines like this. L12 = P1 + a(P2 - P1) L34 = P3 + b(P4 - P3) Where L12 and L34 intersect we must have P1 + a(P2 - P1) = P3 + b(P4 - P3) a(P2 - P1) = (P3 - P1) + b(P4 - P3) Now define vector VP to be perpendicular to (P4 - P3) and take the dot product of both sides with VP. a[(P2 - P1).VP] = (P3 - P1).VP Note that the 'b' term has dropped out. If (P2 - P1).VP = 0 then L12 and L34 are parallel, otherwise we can solve for 'a'. In a similar way we can also make 'a' drop out and solve for 'b.' If 0 < a < 1 the intersection is between P1 and P2. If 0 < b < 1 the intersection is between P3 and P4. To get the intersection point, use 'a' in the equation for L12, or 'b' in the equation for L34. Does that make sense? Write again if you need more help. - Doctor George, The Math Forum http://mathforum.org/dr.math/ |
Search the Dr. Math Library: |
[Privacy Policy] [Terms of Use]
Ask Dr. Math^{TM}
© 1994-2013 The Math Forum
http://mathforum.org/dr.math/