@Test public void testIsNotInsideTriangle() throws Exception { Vector2 p = new Vector2(1.5d, 5d); Vector2 pA = new Vector2(1d, 1d); Vector2 pB = new Vector2(4d, 2d); Vector2 pC = new Vector2(2d, 7d); assertThat(Geometry.isInsideTriangle(p, pA, pB, pC)).isFalse(); }
public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) { Vector2 pointB = new Vector2(pB.x - pA.x, pB.y - pA.y); Vector2 pointC = new Vector2(pC.x - pA.x, pC.y - pA.y); Vector2 point = new Vector2(p.x - pA.x, p.y - pA.y); Double scalar = pointB.x * pointC.y - pointC.x * pointB.y; Double weightA = ( point.x * ( pointB.y - pointC.y ) + point.y * ( pointC.x - pointB.x ) + pointB.x * pointC.y - pointC.x * pointB.y ) / scalar; Double weightB = ( point.x * pointC.y - point.y * pointC.x ) / scalar; Double weightC = ( point.y * pointB.x - point.x * pointB.y ) / scalar; return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC); }
Geometry { public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) { Vector2 pointB = new Vector2(pB.x - pA.x, pB.y - pA.y); Vector2 pointC = new Vector2(pC.x - pA.x, pC.y - pA.y); Vector2 point = new Vector2(p.x - pA.x, p.y - pA.y); Double scalar = pointB.x * pointC.y - pointC.x * pointB.y; Double weightA = ( point.x * ( pointB.y - pointC.y ) + point.y * ( pointC.x - pointB.x ) + pointB.x * pointC.y - pointC.x * pointB.y ) / scalar; Double weightB = ( point.x * pointC.y - point.y * pointC.x ) / scalar; Double weightC = ( point.y * pointB.x - point.x * pointB.y ) / scalar; return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC); } }
Geometry { public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) { Vector2 pointB = new Vector2(pB.x - pA.x, pB.y - pA.y); Vector2 pointC = new Vector2(pC.x - pA.x, pC.y - pA.y); Vector2 point = new Vector2(p.x - pA.x, p.y - pA.y); Double scalar = pointB.x * pointC.y - pointC.x * pointB.y; Double weightA = ( point.x * ( pointB.y - pointC.y ) + point.y * ( pointC.x - pointB.x ) + pointB.x * pointC.y - pointC.x * pointB.y ) / scalar; Double weightB = ( point.x * pointC.y - point.y * pointC.x ) / scalar; Double weightC = ( point.y * pointB.x - point.x * pointB.y ) / scalar; return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC); }  }
Geometry { public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) { Vector2 pointB = new Vector2(pB.x - pA.x, pB.y - pA.y); Vector2 pointC = new Vector2(pC.x - pA.x, pC.y - pA.y); Vector2 point = new Vector2(p.x - pA.x, p.y - pA.y); Double scalar = pointB.x * pointC.y - pointC.x * pointB.y; Double weightA = ( point.x * ( pointB.y - pointC.y ) + point.y * ( pointC.x - pointB.x ) + pointB.x * pointC.y - pointC.x * pointB.y ) / scalar; Double weightB = ( point.x * pointC.y - point.y * pointC.x ) / scalar; Double weightC = ( point.y * pointB.x - point.x * pointB.y ) / scalar; return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC); }  static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC); static boolean isInsideTriangle(Vector2 p, Triangle triangle); static boolean areTrianglesColliding(Triangle triangle1, Triangle triangle2); static Vector2 coordinatesAfterRotation(Vector2 coordinates, Double rotation); }
Geometry { public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) { Vector2 pointB = new Vector2(pB.x - pA.x, pB.y - pA.y); Vector2 pointC = new Vector2(pC.x - pA.x, pC.y - pA.y); Vector2 point = new Vector2(p.x - pA.x, p.y - pA.y); Double scalar = pointB.x * pointC.y - pointC.x * pointB.y; Double weightA = ( point.x * ( pointB.y - pointC.y ) + point.y * ( pointC.x - pointB.x ) + pointB.x * pointC.y - pointC.x * pointB.y ) / scalar; Double weightB = ( point.x * pointC.y - point.y * pointC.x ) / scalar; Double weightC = ( point.y * pointB.x - point.x * pointB.y ) / scalar; return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC); }  static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC); static boolean isInsideTriangle(Vector2 p, Triangle triangle); static boolean areTrianglesColliding(Triangle triangle1, Triangle triangle2); static Vector2 coordinatesAfterRotation(Vector2 coordinates, Double rotation);  }