game-engine/src/main/java/com/jzy/game/engine/math/Intersector.java
/**
	 * Intersects the two lines and returns the intersection point in intersection.
	 * 
	 * @param p1
	 *            The first point of the first line
	 * @param p2
	 *            The second point of the first line
	 * @param p3
	 *            The first point of the second line
	 * @param p4
	 *            The second point of the second line
	 * @param intersection
	 *            The intersection point. May be null.
	 * @return Whether the two lines intersect
	 */
Intersects the two lines and returns the intersection point in intersection.


Intersects the two lines and returns the intersection point in intersection .
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 d = (y4 - y3) * (x2 - x1) - (x4 - x3) * (y2 - y1);
		if (d == 0)
			return false;
		if (intersection != null) {
			float ua = ((x4 - x3) * (y1 - y3) - (y4 - y3) * (x1 - x3)) / d;
			intersection.set(x1 + (x2 - x1) * ua, y1 + (y2 - y1) * ua);
		}
		return true;
	}
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 d = ( y4 - y3 ) * ( x2 - x1 ) - ( x4 - x3 ) * ( y2 - y1 ) ; if ( d == 0 ) return false ; if ( intersection != null ) { float ua = ( ( x4 - x3 ) * ( y1 - y3 ) - ( y4 - y3 ) * ( x1 - x3 ) ) / d ; intersection . set ( x1 + ( x2 - x1 ) * ua , y1 + ( y2 - y1 ) * ua ) ; } return true ; }
Intersects the two lines and returns the intersection point in intersection.
Intersects the two lines and returns the intersection point in intersection .