Given a triangle and a point inside the triangle in Cartesian coordinate system, I compute the Barycentric coordinate of the point like this:
double v2_1[3], v2_3[3], v2_t[3];
double bary[3];
vtkMath::Subtract(p1, p2, v2_1);
vtkMath::Subtract(p3, p2, v2_3);
vtkMath::Subtract(t, p2, v2_t);
float d00 = vtkMath::Dot(v2_1, v2_1);
float d01 = vtkMath::Dot(v2_1, v2_3);
float d11 = vtkMath::Dot(v2_3, v2_3);
float denom = d00 * d11 - d01 * d01;
float d20 = vtkMath::Dot(v2_t, v2_1);
float d21 = vtkMath::Dot(v2_t, v2_3);
bary[0] = (d11 * d20 - d01 * d21) / denom;
bary[1] = (d00 * d21 - d01 * d20) / denom;
bary[2] = 1.0f - bary[0] - bary[1];
return bary;
Now, how can I use the values in bary
to interpolate the vertex normal at p1
, p2
and p3
? Specifically, I'm confused which coefficient belongs to which vertex.