Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualAressera

Posted 04 February 2013 - 05:00 PM

Here's a faster version for computing barycentric coordinates, adapted from Ericson's Real Time Collision Detection book:

 

Vector3 computeBarycentricCoordinates( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& point )
{
	Vector3 e0 = v2 - v1;
	Vector3 e1 = v3 - v1;
	Vector3 e2 = point - v1;
	
	Real d00 = math::dot( e0, e0 );
	Real d01 = math::dot( e0, e1 );
	Real d11 = math::dot( e1, e1 );
	Real d20 = math::dot( e2, e0 );
	Real d21 = math::dot( e2, e1 );
	Real inverseDenom = Real(1) / (d00*d11 - d01*d01);
	
	Real v = (d11*d20 - d01*d21) * inverseDenom;
	Real w = (d00*d21 - d01*d20) * inverseDenom;
	Real u = Real(1) - v - w;
	
	return Vector3(	u, v, w );
}

#1Aressera

Posted 04 February 2013 - 04:57 PM

Here's a faster version for computing barycentric coordinates, adapted from Dave Eberly's Real Time Collision Detection book:

 

Vector3 computeBarycentricCoordinates( const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& point )
{
	Vector3 e0 = v2 - v1;
	Vector3 e1 = v3 - v1;
	Vector3 e2 = point - v1;
	
	Real d00 = math::dot( e0, e0 );
	Real d01 = math::dot( e0, e1 );
	Real d11 = math::dot( e1, e1 );
	Real d20 = math::dot( e2, e0 );
	Real d21 = math::dot( e2, e1 );
	Real inverseDenom = Real(1) / (d00*d11 - d01*d01);
	
	Real v = (d11*d20 - d01*d21) * inverseDenom;
	Real w = (d00*d21 - d01*d20) * inverseDenom;
	Real u = Real(1) - v - w;
	
	return Vector3(	u, v, w );
}

PARTNERS