Game Development Reference
In-Depth Information
In 3D, we can use the cross product to compute the area of a triangle.
Recall from Section 2.12.2 that the magnitude of the cross product of two
vectors a and b is equal to the area of the parallelogram formed on two
sides by a and b . Since the area of a triangle is half the area of the enclosing
parallelogram, we have a simple way to calculate the area of the triangle.
Given two edge vectors from the triangle, e 1 and e 2 , the area of the triangle
is given by
e 1
× e 2
A =
.
(9.16)
2
Notice that if we extend a 2D triangle into 3D by assuming z = 0, then
Equation (9.15) and Equation (9.16) are equivalent.
9.6.3 Barycentric Space
Even though we certainly use triangles in 3D, the surface of a triangle lies
in a plane and is inherently a 2D object. Moving around on the surface of
a triangle that is arbitrarily oriented in 3D is somewhat awkward. It would
be nice to have a coordinate space that is related to the surface of the
triangle and is independent of the 3D space in which the triangle “lives.”
Barycentric space is just such a coordinate space. Many practical problems
that arise when making video games, such as interpolation and intersec-
tion, can be solved by using barycentric coordinates. We are introducing
barycentric coordinates in the context of triangles here, but they have wide
applicability. In fact, we meet them again in a slightly more general form
in the context of 3D curves in Chapter 13.
Any point in the plane of a triangle can be expressed as a weighted
average of the vertices. These weights are known as barycentric coordi-
nates. The conversion from barycentric coordinates (b 1 ,b 2 ,b 3 ) to standard
3D space is defined by
Computing a 3D point
from barycentric
coordinates
(b 1 ,b 2 ,b 3 ) ≡ b 1 v 1 + b 2 v 2 + b 3 v 3 .
(9.17)
Of course, this is simply a linear combination of some vectors. Section 3.3.3
showed how ordinary Cartesian coordinates can also be interpreted as
a linear combination of the basis vectors, but the subtle distinction be-
tween barycentric coordinates and ordinary Cartesian coordinates is that
for barycentric coordinates the sum of the coordinates is restricted to be
unity:
b 1 + b 2 + b 3 = 1.
This normalization constraint removes one degree of freedom, which is why
even though there are three coordinates, it is still a 2D space.
The values b 1 , b 2 , b 3 are the “contributions” or “weights” that each
vertex contributes to the point. Figure 9.18 shows some examples of points
and their barycentric coordinates.
 
Search WWH ::




Custom Search