What's the most efficient way to find barycentric coordinates?

Posted by bobobobo on Game Development See other posts from Game Development or by bobobobo
Published on 2012-02-12T02:14:36Z Indexed on 2014/08/22 16:38 UTC
Read the original article Hit count: 321

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.

bary

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!

© Game Development or respective owner

Related posts about barycentric-coordinates