| 1302 | } |
| 1303 | |
| 1304 | function AreLinesColliding(x1, y1, x2, y2, x3, y3, x4, y4) { |
| 1305 | let uA = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); |
| 1306 | let uB = ((x2 - x1) * (y1 - y3) - (y2 - y1) * (x1 - x3)) / ((y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1)); |
| 1307 | if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) { |
| 1308 | let intersectionX = x1 + (uA * (x2 - x1)); |
| 1309 | let intersectionY = y1 + (uA * (y2 - y1)); |
| 1310 | return [true, intersectionX, intersectionY]; |
| 1311 | } |
| 1312 | return [false, 0, 0] |
| 1313 | |
| 1314 | } |