Find Out If Two Line Segments Intersect
I know this should be pretty simple, but I can't figure out the following: I want to write a function that checks if two one-dimensional lines intersect. if they intersect return '
Solution 1:
The lines intersect if either: a) The first line starts before the second and ends after the second one starts. b) The other way around. So:
functionoverlap(A1,A2,B1,B2) {
return (A1<=B1 && A2>=B1) || (B1<=A1 && B2>=A1);
}
Or:
functionoverlap(A1,A2,B1,B2) {
returnA1<=B1?A2>=B1:B2>=A1;
}
Post a Comment for "Find Out If Two Line Segments Intersect"