Vector3Barycenter function
Barycentric coordinates (u, v, w) of p relative to triangle (a, b, c).
Implementation
Vector3 Vector3Barycenter(Vector3 p, Vector3 a, Vector3 b, Vector3 c) {
final v0 = b - a, v1 = c - a, v2 = p - a;
final d00 = v0.dot(v0), d01 = v0.dot(v1), d11 = v1.dot(v1);
final d20 = v2.dot(v0), d21 = v2.dot(v1);
final denom = d00 * d11 - d01 * d01;
final bv = (d11 * d20 - d01 * d21) / denom;
final bw = (d00 * d21 - d01 * d20) / denom;
return Vector3(1 - bv - bw, bv, bw);
}