Given two line segments the problem is to find an intersection point of corresponding lines (assuming that they are not parallel or coincide).
There is a Wikipedia article which gives us exact formulas, but there are two of them: one that uses
t ratio and approaches intersection point from first line segment and the other -- uses
u and the second line segment. How can I select which one to use in my scenario?
For example: my initial implementation which always used
t failed on
first_segment = Segment(start=Point(x=-5, y=0), end=Point(x=72057594037954921, y=0)) second_segment = Segment(start=Point(x=0, y=0), end=Point(x=0, y=3))
which is incorrect, but when I switch to use
u or change order of arguments it gives me correct
So my question is: is there robust way to calculate intersection point?