Graphics Reference
In-Depth Information
+ - -
A
+ + -
+ - +
+ + +
B
- + -
C
- + +
- - +
Figure 3.10 Barycentric coordinates divide the plane of the triangle ABC into seven regions
based on the sign of the coordinate components.
vertices to the xy , xz ,or yz plane. To avoid degeneracies, the projection is made to
the plane where the projected areas are the greatest. The largest absolute component
value of the triangle normal indicates which component should be dropped during
projection.
inline float TriArea2D(float x1, float y1, float x2, float y2, float x3, float y3)
{
return (x1-x2)*(y2-y3) - (x2-x3)*(y1-y2);
}
// Compute barycentric coordinates (u, v, w) for
// point p with respect to triangle (a, b, c)
void Barycentric(Point a, Point b, Point c, Point p, float &u, float &v, float &w)
{
// Unnormalized triangle normal
Vector m = Cross(b - a,c-a);
// Nominators and one-over-denominator for u and v ratios
float nu, nv, ood;
// Absolute components for determining projection plane
float x = Abs(m.x), y = Abs(m.y), z = Abs(m.z);
// Compute areas in plane of largest projection
if(x>=y&&x>=z){
// x is largest, project to the yz plane
nu = TriArea2D(p.y, p.z, b.y, b.z, c.y, c.z);
// Area of PBC in yz plane
nv = TriArea2D(p.y, p.z, c.y, c.z, a.y, a.z);
// Area of PCA in yz plane
ood = 1.0f / m.x;
// 1/(2*area of ABC in yz plane)
 
Search WWH ::




Custom Search