What's the most efficient way to find barycentric coordinates?
- by bobobobo
In my profiler, finding barycentric coordinates is apparently somewhat of a bottleneck. I am looking to make it more efficient.
It follows the method in shirley, where you compute the area of the triangles formed by embedding the point P inside the triangle.
Code:
Vector Triangle::getBarycentricCoordinatesAt( const Vector & P ) const
{
Vector bary ;
// The area of a triangle is
real areaABC = DOT( normal, CROSS( (b - a), (c - a) ) ) ;
real areaPBC = DOT( normal, CROSS( (b - P), (c - P) ) ) ;
real areaPCA = DOT( normal, CROSS( (c - P), (a - P) ) ) ;
bary.x = areaPBC / areaABC ; // alpha
bary.y = areaPCA / areaABC ; // beta
bary.z = 1.0f - bary.x - bary.y ; // gamma
return bary ;
}
This method works, but I'm looking for a more efficient one!