Determine if two lines intersect
I've seen many postings here on stackoverflow, which are discussing this
topic. I took a solution from stackoverflow, but I couldn't find the
posting. It was to say: If two lines are intersecting, then the
crossproduct produces for the left and the right side two different
results. One positive and one negative. Otherwise both have the same sign.
So far it is okay. The used formula is, where AB is one line and CD
another.
dotproductleft = (B.x-A.x)*(C.y-B.y)-(B.y-A.y)*(C.x-B.x)
dotproductright = (B.x-A.x)*(D.y-B.y)-(B.y-A.y)*(D.x-B.x)
If I calculate this for the following given GPS coordinates I get an
intersection, in a case where no intersection is possible.
A: x: 15.4433917 y: 47.0697272
B: x: 15.4433661 y: 47.0697722
C: x: 15.4434363 y: 47.0696776
D: x: 15.442966 y: 47.0700098
If I draw it on Google Maps Engine, I can see that there definitely no
intersection between these lines.
The results for dotproductleft: -7.372399999828474E-10 and for
dotproductright: 1.1921940000328E-8
It is working for other examples very well, but here I've seen that it is
not working right. But I couldn't spot any error in the formula.
No comments:
Post a Comment