This discussion is archived
3 Replies Latest reply: Oct 30, 2012 6:15 AM by 800268 RSS

Determining intersection of two lines not working as intended ...

835847 Newbie
Currently Being Moderated
Two Line2D.Float lines sharing a common vertex and oriented to each other through 360 degrees but not collinear. Trying Line2D.intersectsLine(foo) is true. I would not consider two lines sharing a common end-point as intersected but Java does. I take it that any line whose endpoint lay within another's length is mathematically an intersection. Problem is, I need a test for intersection to be two lines crossing each other whose endpoints are not common but share a common point that lay within their length, such as two lines forming an X.

Any ideas about how I may go about building such a test?
  • 1. Re: Determining intersection of two lines not working as intended ...
    rp0428 Guru
    Currently Being Moderated
    >
    Any ideas about how I may go about building such a test?
    >
    You already defined the ruleset for the test in your description. See if Java thinks they intersect. If they don't you have your answer. Otherwise you have to check all four endpoints to see if any of them fall on the other line segment.

    1. use intersectsLine - if false then segments do not interesect - you are done, else go to step 2

    2. check each endpont of segment 1 to see if it matches either endpoint of segment 2 - if true segments do not intersect based on YOUR definition - you are done, else go to step 3

    3. use ptSegDist to measure the distance from each endpoint of segment 1 from segment 2 - if 0 segments do not intersect based on YOUR definition - you are done, else go to step 4

    4. use ptSegDist to measure the distance from each endpoint of segment 2 from segment 1 - if 0 segments do not intersect based on YOUR definition - you are done, else go to step 5

    5. segments intersect based on YOUR definition
  • 2. Re: Determining intersection of two lines not working as intended ...
    835847 Newbie
    Currently Being Moderated
    Thank you for your response. I did exactly what you stated before reading your response. I test if the starting or ending endpoints of a line segment are joined to another line segments starting or ending points. If so, then the lines do not intersect. I believe the reason I had to do this is because Java's intersectsLine(Line2D) method assumes the lines are infinite in length and thus if extending two lines through common endpoints, one can force them to intersect at a common point.
  • 3. Re: Determining intersection of two lines not working as intended ...
    800268 Expert
    Currently Being Moderated
    Always Learning wrote:
    I believe the reason I had to do this is because Java's intersectsLine(Line2D) method assumes the lines are infinite in length and thus if extending two lines through common endpoints, one can force them to intersect at a common point.
    No it does not assume that. As said by rp0428, it uses a different definition of intersection then yours where the lines like T (and not only like X or +) intersect. The T lines touch, the X lines cross; both intersect.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points