Graphics Reference
In-Depth Information
Here we've assumed the existence of a matrix-vector product procedure and a
pseudoinverse procedure, as provided by most numerical packages.
The two procedures above can be combined, of course, to produce the function
value at a point P that's specified in xyz -coordinates.
Input:
• A triangle mesh in the form of an n
×
3 table, vtable , of vertices
•A k
3 table, ftable , of triangles, where each row of ftable contains
three indices into vtable
•An n
×
1 table, fntable , of function values at the vertices of the mesh
• A point P of the mesh, expressed by giving the index, t , of the triangle in
which the point lies, and its coordinates in 3-space
×
Output:
• The value of the function defined by the function table at the point P
1
2
3
4
5
6
7
8
double meshinterp2(double[,] vtable, int[,] ftable, double[] fntable,
int t, double p[3])
{
double[] barycentricCoords =
barycentricCoordinates(vtable, ftable, t, p);
return meshinterp2(vtable, ftable, fntable, t,
barycentricCoords[0], barycentricCoords[1], barycentricCoords[2]);
}
Of course, the same idea can be applied to the ray-intersect-triangle code of
Section 7.9.2, where we first computed the barycentric coordinates (
) of
the ray-triangle intersection point Q with respect to the triangle ABC , and then
computed the point Q itself as the barycentric weighted average of A , B , and C .
If instead we had function values f A , f B , and f C at those points, we could have
computed the value at Q as f Q =
α
,
β
,
γ
f C . Notice that this means we can
compute the interpolated function value f Q at the intersection point without ever
computing the intersection point itself!
Computing barycentric coordinates (
α
f A +
β
f B +
γ
α
,
β
,
γ
) for a point P of a triangle ABC ,
R 2 , is somewhat simpler than the corresponding problem in
3-space (see Figure 9.3). We know that the lines of constant
where A , B , C
α
are parallel to
BC .Ifwelet n =( C
B ) , then the function defined by f ( P )=( P
B )
·
n is
also constant on lines parallel to B
C . Scaling this down by f ( A ) gives us the
function we need: It's zero on line BC , and it's one at A .Sowelet
( P
B )
·
n
g : R 2
R : P
n ,
(9.11)
( A
B )
·
and the value of g ( P ) is just
α
. A similar computation works for
β
and
γ
.
The resultant code looks like this:
1
2
3
4
5
6
7
8
double[3] barycenter2D(Point P, Point A, Point B, Point C)
C[2])
{
double[] result = new double[3];
result[0] = helper(P, A, B, C);
result[1] = helper(P, B, C, A);
result[2] = helper(P, C, A, B);
return result;
 
Search WWH ::




Custom Search