barycenter static method

Computes the barycentric coordinates of point p relative to triangle (a, b, c).

Implementation

static Vector3Base barycenter(Vector3Base p, Vector3Base a, Vector3Base b, Vector3Base c) {
  final v0 = b.sub(a);
  final v1 = c.sub(a);
  final v2 = p.sub(a);
  final d00 = v0.dotProduct(v0);
  final d01 = v0.dotProduct(v1);
  final d11 = v1.dotProduct(v1);
  final d20 = v2.dotProduct(v0);
  final d21 = v2.dotProduct(v1);
  final denom = d00*d11 - d01*d01;
  final y = (d11*d20 - d01*d21)/denom;
  final z = (d00*d21 - d01*d20)/denom;
  final x = 1.0 - (z + y);
  return createFactory(x, y, z);
}