Archived post by Reinhold

looks like vtx0 is {0, 0, 0}, vtx1 is {1, 0, 0}, vtx2 is {0, 1, 0} and vtx3 is {0, 0, 1}. and any point in between is just a linear interpolation of these four values. shouldn’t take too long to get there now

got it working now. building a matrix from the tet vertex positions and running an inverse transform on the point position puts the sample point into the normalized barycentric space, i.e. the new point position is the barycentric coordinate

“` int prims[]; vector p = v@P; vector vtxp[];
prims = primfind(1, v@P, v@P);
foreach(int prim; prims) { for(int i=0; i<4; i++) { vtxp[i] = vector(point(1, "P", primpoint(1, prim, i))); } matrix3 mat = set(vtxp[1] - vtxp[0], vtxp[2] - vtxp[0], vtxp[3] - vtxp[0]); p -= vtxp[0]; p *= invert(mat); } v@uv = p;“`