staticGetBarycoord static method
Vector3
staticGetBarycoord(
- Vector3 point,
- Vector3 a,
- Vector3 b,
- Vector3 c,
- Vector3 target,
Implementation
static Vector3 staticGetBarycoord(Vector3 point, Vector3 a, Vector3 b, Vector3 c, Vector3 target) {
_v0.sub2(c, a);
_v1.sub2(b, a);
_v2.sub2(point, a);
var dot00 = _v0.dot(_v0);
var dot01 = _v0.dot(_v1);
var dot02 = _v0.dot(_v2);
var dot11 = _v1.dot(_v1);
var dot12 = _v1.dot(_v2);
var denom = (dot00 * dot11 - dot01 * dot01);
// collinear or singular triangle
if (denom == 0) {
// arbitrary location outside of triangle?
// not sure if this is the best idea, maybe should be returning null
return target..setValues(-2, -1, -1);
}
var invDenom = 1 / denom;
var u = (dot11 * dot02 - dot01 * dot12) * invDenom;
var v = (dot00 * dot12 - dot01 * dot02) * invDenom;
// barycentric coordinates must always sum to 1
return target..setValues(1 - u - v, v, u);
}