Graphics Reference
In-Depth Information
float d21 = Dot(v2, v1);
float denom = d00 * d11 - d01 * d01;
v = (d11 * d20 - d01 * d21) / denom;
w = (d00 * d21 - d01 * d20) / denom;
u=1.0f-v-w;
}
If several points are tested against the same triangle, the terms d00 , d01 , d11 , and
denom only have to be computed once, as they are fixed for a given triangle.
The barycentric coordinates can be computed for a point with respect to a simplex
(Section 3.8) of any dimension. For instance, given a tetrahedron specified by the
vertices A , B , C , and D , the barycentric coordinates ( u , v , w , x ) specify a point P in 3D
space, P
=
uA
+
vB
+
wC
+
xD with u
+
v
+
w
+
x
=
1. If 0
u , v , w , x
1, then P is
inside the tetrahedron.
Given the points specified as A
=
( a x , a y , a z ), B
=
( b x , b y , b z ), C
=
( c x , c y , c z ),
D
( p x , p y , p z ), the barycentric coordinates can be solved for by
setting up a system of linear equations:
=
( d x , d y , d z ), and P
=
a x u
+
b x v
+
c x w
+
d x x
=
p x
a y u
+
b y v
+
c y w
+
d y x
=
p y
a z u
+
b z v
+
c z w
+
d z x
=
p z
u
+
v
+
w
+
x
=
1
Alternatively, by subtracting A from both sides of P
=
uA
+
vB
+
wC
+
xD — giving
P
A
=
v ( B
A )
+
w ( C
A )
+
x ( D
A )
— it follows that three of the four barycentric coordinate components can be obtained
by solving
( b x
a x ) v
+ (
c x
a x
)
w
+ (
d x
a x
)
x
=
p x
a x ,
+ c y
a y w
+ d y
a y x
=
( b y
a y ) v
p y
a y , and
( b z
a z ) v
+ (
c z
a z
)
w
+ (
d z
a z
)
x
=
p z
a z
=
(with the fourth component given by u
x ). Either system is easily solved
using Cramer's rule or Gaussian elimination. For example, in the former system the
coordinates are given by Cramer's rule as the ratios
1
v
w
=
u
d PBCD / d ABCD ,
 
Search WWH ::




Custom Search