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 "true", else return "false".
I have two lines named A and B. Each line has two endpoints (A1, A2 / B1, B2). My logic is that if the two lines intersect "A2 >= B1 && B2 >= A1" is true. However, that doesn't seem to work.
function linesIntersect (A1, A2, B1, B2) {
if (A2 >= B1 && B2 >= A1) {
return true
} else {
return false
}
}
Any help is welcome. Thanks!