MathUtils { public static float barryCentric(Vector3 p1, Vector3 p2, Vector3 p3, Vector2 pos) { float det = (p2.z - p3.z) * (p1.x - p3.x) + (p3.x - p2.x) * (p1.z - p3.z); float l1 = ((p2.z - p3.z) * (pos.x - p3.x) + (p3.x - p2.x) * (pos.y - p3.z)) / det; float l2 = ((p3.z - p1.z) * (pos.x - p3.x) + (p1.x - p3.x) * (pos.y - p3.z)) / det; float l3 = 1.0f - l1 - l2; return l1 * p1.y + l2 * p2.y + l3 * p3.y; }  static float barryCentric(Vector3 p1, Vector3 p2, Vector3 p3, Vector2 pos); static float dst(float x1, float y1, float x2, float y2); static float angle(float x1, float y1, float x2, float y2);  }
@Test public void barryCentric() throws Exception { Vector3 a = new Vector3(1.0f, 0.0f, 0.0f); Vector3 b = new Vector3(0.0f, 1.0f, 0.0f); Vector3 c = new Vector3(0.0f, 0.0f, 1.0f); Vector2 pos = new Vector2(0.0f, 0.0f); assertEquals(1.0f, MathUtils.barryCentric(a, b, c, pos), 0.0f); }