Sign in to follow this  
DesignerX

Limited Intersection

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this