// calcuate barycentric coordinates (u,v,w) for point p with respect to triangle (a,b,c) // use 3d PVector to store u,v,w // https://en.wikipedia.org/wiki/Barycentric_coordinate_system PVector getBaryCentric(PVector p, PVector a, PVector b, PVector c) { PVector v0 = PVector.sub(b, a); PVector v1 = PVector.sub(c, a); PVector v2 = PVector.sub(p, a); float den = v0.x * v1.y - v1.x * v0.y; float v = (v2.x * v1.y - v1.x * v2.y) / den; float w = (v0.x * v2.y - v2.x * v0.y) / den; float u = 1.0f - v - w; return new PVector(u, v, w); }