Graphics Reference
In-Depth Information
// If P outside CA and within feature region of CA,
// return projection of P onto CA
if (vb <= 0.0f && tnom >= 0.0f && tdenom >= 0.0f)
return a + tnom / (tnom + tdenom) * ac;
// P must project inside face region. Compute Q using barycentric coordinates
floatu=va/(va+vb+vc);
floatv=vb/(va+vb+vc);
floatw=1.0f-u-v; //=vc/(va+vb+vc)
returnu*a+v*b+w*c;
}
As presented, this code contains four cross-product calls. Because cross products
are often more expensive to calculate than dot products, it is worthwhile exploring
whether these can be replaced by more economical expressions. It turns out that the
Lagrange identity
( a
×
b )
·
( c
×
d )
=
( a
·
c )( b
·
d )
( a
·
d )( b
·
c )
can be used to express the three scalar triple products
Vector n = Cross(b - a,c-a);
float va = Dot(n, Cross(b - p, c - p));
float vb = Dot(n, Cross(c - p, a - p));
float vc = Dot(n, Cross(a - p, b - p));
in terms of the six dot products
float d1 = Dot(b - a,p-a);
float d2 = Dot(c - a,p-a);
float d3 = Dot(b - a,p-b);
float d4 = Dot(c - a,p-b);
float d5 = Dot(b - a,p-c);
float d6 = Dot(c - a,p-c);
as
float va = d3*d6 - d5*d4;
float vb = d5*d2 - d1*d6;
float vc = d1*d4 - d3*d2;
 
Search WWH ::




Custom Search