Limited Intersection

Started by
1 comment, last by DesignerX 16 years, 8 months ago
I have two 2D points (x1, y1) (x2, y2) and I have an infinite line . I want to find if the infinite line itersects the line rendered by the two given points (lets call it L). If the infinite line intesrect a part of L that is not between the given points I want to detect that). What is the simpliest (and efficient) way to achieve that ? thx alot.
There is nothing that can't be solved. Just people that can't solve it. :)
Advertisement
Lets call the two points P1 and P2 for convenience:

1. compute a second line equation that passes through the two points
2. Find the intersection of the two infinite lines. If no intersection, you are done.
3. If the two lines intersect, compute the coordinate of the intersection point, and call it PInt
4. Compute a vector V = PInt - P1
5. Let L = P2 - P1
6. If the dot product of V and L is negative, then the intersection point is on the opposite side of L from P2, and so is off the line
7. If the dot product of V and L is positive, then the intersection point is on the same side as P2 and might be on the line, so....
8. ...compare the square of the length of V and the square of the length of L. If the square of the length of V is less than or equal to the square of the length of L, then the intersection point lies on L, otherwise, the intersection point is further away than P2 and therefore is off of L.

Hope that helps!
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
thx alot man.
There is nothing that can't be solved. Just people that can't solve it. :)

This topic is closed to new replies.

Advertisement