Graphics Reference
In-Depth Information
triangle ABC , the barycentric coordinates of the vertices A , B , and C are (1, 0, 0),
(0, 1, 0), and (0, 0, 1), respectively. In general, a point with barycentric coordinates
( u , v , w ) is inside (or on) the triangle if and only if 0
u , v , w
1, or alternatively
if and only if 0
v
1, 0
w
1, and v
+
w
1. That barycentric coordinates
actually parameterize the plane follows from P
=
uA
+
vB
+
wC really just being a
reformulation of P
=
A
+
v ( B
A )
+
w ( C
A ), with v and w arbitrary, as
P
=
A
+
v ( B
A )
+
w ( C
A )
=
(1
v
w ) A
+
vB
+
wC .
In the latter formulation, the two independent direction vectors AB and AC form a
coordinate system with origin A , allowing any point P in the plane to be parame-
terized in terms of v and w alone. Clearly, barycentric coordinates is a redundant
representation in that the third component can be expressed in terms of the first two.
It is kept for reasons of symmetry.
To solve for the barycentric coordinates, the expression P
=
A
+
v ( B
A )
+
w ( C
A ) — or equivalently v ( B
A )
+
w ( C
A )
=
P
A — can be written as
v v 0
2
system of linear equations can be formed by taking the dot product of both sides
with both v 0 and v 1 :
+
w v 1
=
v 2 , where v 0
=
B
A , v 1
=
C
A , and v 2
=
P
A . Now, a 2
×
+
) ·
=
·
(
v v 0
w v 1
v 0
v 2
v 0 , and
(
v v 0
+
w v 1
) ·
v 1
=
v 2
·
v 1 .
Because the dot product is a linear operator, these expressions are equivalent to
v
(
v 0 ·
v 0 ) +
w
(
v 1 ·
v 0 ) =
v 2 ·
v 0 , and
v
(
v 0 ·
v 1 ) +
w
(
v 1 ·
v 1 ) =
v 2 ·
v 1 .
This system is easily solved with Cramer's rule. The following code is an implemen-
tation computing the barycentric coordinates using this method.
// 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)
{
Vector v0=b-a,v1=c-a,v2=p-a;
float d00 = Dot(v0, v0);
float d01 = Dot(v0, v1);
float d11 = Dot(v1, v1);
float d20 = Dot(v2, v0);
 
Search WWH ::




Custom Search