class Geometry {

    public static boolean isInsideTriangle(Vector2 p, Vector2 pA, Vector2 pB, Vector2 pC) {
        // Move origin of coordinates to point A
        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);

        // Calculate scalar
        Double scalar = pointB.x * pointC.y - pointC.x * pointB.y;

        //  Calculate the 3 Barycentric weights
        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;

        // Point is inside triangle if and only if the 3 weights are between 0 and 1
        return isBetweenZeroAndOne(weightA) && isBetweenZeroAndOne(weightB) && isBetweenZeroAndOne(weightC);
    }

}

class GeometryTest {

    @Test
    public void testIsInsideTriangle() throws Exception {

        Vector2 p = new Vector2(2d, 3d);
        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)).isTrue();
    }

}