l1s is line 1 start, l1f is line 1 finish, the rest goes accordingly.
Copy to clipboard
bool vec2LinesIntersect ( Vector2 l1s, Vector2 l1f, Vector2 l2s, Vector2 l2f ){ Vector2 v1 = l1f - l1s; Vector2 v2 = l2s - l1s; Vector2 v3 = l2f - l1s; Real crossProd1 = v1.crossProduct(v2); Real crossProd2 = v1.crossProduct(v3); if ((crossProd1 > 0 && crossProd2 < 0) || (crossProd1 < 0 && crossProd2 > 0) || (crossProd1 == 0 && crossProd2 == 0)) { v1 = l2s - l2f; v2 = l1s - l2f; v3 = l1f - l2f; crossProd1 = v1.crossProduct(v2); crossProd2 = v1.crossProduct(v3); if ((crossProd1 > 0 && crossProd2 < 0) || (crossProd1 < 0 && crossProd2 > 0) || (crossProd1 == 0 && crossProd2 == 0)) { return true; } } return false; }