0

I'm facing a problem to get the range segment when two segment lines are colliding. If they just cross each other in one point, I'm using the algorithm provided by Gavin in this answer from the book Tricks of the Windows Game Programming Gurus (2nd Edition), but this code doesn't works when the segmets overlaps in two points, like the image bellow shows.

Image

How can I get the red segment when the lines are colliding in this situation?

Community
  • 1
  • 1
Kaz
  • 31
  • 8
  • Most algorithms will bail out for this, because the lines are parallel, and strictly speaking, there **is** no intersection. You'll also have to deal with some epsilon-errors, where one point would (mathematically) be **on** the line, but due to limited floating point precision, actually has a distance of 0.000021323 to the line... If this is not highly time critical (and I doubt that it is), I'd just check all four points, and if `point.distanceTo(otherLine) < 1e6` for two of them, just use these as the endpoints for the overlap segment. – Marco13 Apr 12 '17 at 02:02
  • Thank you. You gave me the idea: I made a function to detect if a point touches a line, so then I only need to check which points of segment A touch segment B and vice-versa. – Kaz Apr 13 '17 at 20:32

0 Answers0