• Advertisement
Sign in to follow this  

Limited Intersection

This topic is 3859 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement