@Test public void testIntersectLinesWithIntersectingLines() { Vector2 line1Start = new Vector2(0, 0); Vector2 line1End = new Vector2(0, 32); Vector2 line2Start = new Vector2(-32, 16); Vector2 line2End = new Vector2(32, 16); Assert.assertEquals(true, Intersector.intersectLines(line1Start, line1End, line2Start, line2End, new Vector2())); line1Start = new Vector2(100, 100); line1End = new Vector2(150, 100); line2Start = new Vector2(50, 100); line2End = new Vector2(50, 200); Assert.assertEquals(true, Intersector.intersectLines(line1Start, line1End, line2Start, line2End, new Vector2())); }
public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection) { float x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, x3 = p3.x, y3 = p3.y, x4 = p4.x, y4 = p4.y; float det3 = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4); if (det3 == 0) return false; float det1 = det(x1, y1, x2, y2); float det2 = det(x3, y3, x4, y4); float x = det(det1, x1 - x2, det2, x3 - x4) / det3; float y = det(det1, y1 - y2, det2, y3 - y4) / det3; intersection.x = x; intersection.y = y; return true; }
Intersector { public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection) { float x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, x3 = p3.x, y3 = p3.y, x4 = p4.x, y4 = p4.y; float det3 = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4); if (det3 == 0) return false; float det1 = det(x1, y1, x2, y2); float det2 = det(x3, y3, x4, y4); float x = det(det1, x1 - x2, det2, x3 - x4) / det3; float y = det(det1, y1 - y2, det2, y3 - y4) / det3; intersection.x = x; intersection.y = y; return true; } }
Intersector { public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection) { float x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, x3 = p3.x, y3 = p3.y, x4 = p4.x, y4 = p4.y; float det3 = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4); if (det3 == 0) return false; float det1 = det(x1, y1, x2, y2); float det2 = det(x3, y3, x4, y4); float x = det(det1, x1 - x2, det2, x3 - x4) / det3; float y = det(det1, y1 - y2, det2, y3 - y4) / det3; intersection.x = x; intersection.y = y; return true; }  }
Intersector { public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection) { float x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, x3 = p3.x, y3 = p3.y, x4 = p4.x, y4 = p4.y; float det3 = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4); if (det3 == 0) return false; float det1 = det(x1, y1, x2, y2); float det2 = det(x3, y3, x4, y4); float x = det(det1, x1 - x2, det2, x3 - x4) / det3; float y = det(det1, y1 - y2, det2, y3 - y4) / det3; intersection.x = x; intersection.y = y; return true; }  static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection); static boolean intersectLineSegments(float segAX1, float segAY1, float segAX2, float segAY2, float segBX1,
                                                float segBY1, float segBX2, float segBY2); static boolean intersects(Rectangle rectangle, Circle circle); static boolean containsPolygon(Polygon p1, Polygon p2); static boolean intersectSegmentPolygon(Vector2 p1, Vector2 p2, float[] vertices); }
Intersector { public static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection) { float x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y, x3 = p3.x, y3 = p3.y, x4 = p4.x, y4 = p4.y; float det3 = det(x1 - x2, y1 - y2, x3 - x4, y3 - y4); if (det3 == 0) return false; float det1 = det(x1, y1, x2, y2); float det2 = det(x3, y3, x4, y4); float x = det(det1, x1 - x2, det2, x3 - x4) / det3; float y = det(det1, y1 - y2, det2, y3 - y4) / det3; intersection.x = x; intersection.y = y; return true; }  static boolean intersectLines(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Vector2 intersection); static boolean intersectLineSegments(float segAX1, float segAY1, float segAX2, float segAY2, float segBX1,
                                                float segBY1, float segBX2, float segBY2); static boolean intersects(Rectangle rectangle, Circle circle); static boolean containsPolygon(Polygon p1, Polygon p2); static boolean intersectSegmentPolygon(Vector2 p1, Vector2 p2, float[] vertices);  }