Game Development Reference
In-Depth Information
have zero area. The formulas for the areas under each edge are
A( e 1 ) = (y 3 + y 2 )(x 3 − x 2 )
2
,
A( e 2 ) = (y 1 + y 3 )(x 1 − x 3 )
2
,
A( e 3 ) = (y 2 + y 1 )(x 2 − x 1 )
2
.
By summing the signed areas of the three trapezoids, we arrive at the area
of the triangle itself. In fact, the same idea can be used to compute the
area of a polygon with any number of sides.
We assume a clockwise ordering of the vertices around the triangle.
Enumerating the vertices in the opposite order flips the sign of the area.
With these considerations in mind, we sum the areas of the trapezoids to
compute the signed area of the triangle:
A = A( e 1 ) + A( e 2 ) + A( e 3 )
= (y 3 + y 2 )(x 3 − x 2 ) + (y 1 + y 3 )(x 1 − x 3 ) + (y 2 + y 1 )(x 2 − x 1 )
2
0
1
(y 3 x 3 − y 3 x 2 + y 2 x 3 − y 2 x 2 )
+ (y 1 x 1 − y 1 x 3 + y 3 x 1 − y 3 x 3 )
+ (y 2 x 2 − y 2 x 1 + y 1 x 2 − y 1 x 1 )
@
A
=
2
−y 3 x 2 + y 2 x 3 − y 1 x 3 + y 3 x 1 − y 2 x 1 + y 1 x 2
2
= y 1 (x 2 − x 3 ) + y 2 (x 3 − x 1 ) + y 3 (x 1 − x 2 )
2
=
.
We can actually simplify this just a bit further. The basic idea is to
realize that we can translate the triangle without affecting the area. We
make an arbitrary choice to shift the triangle vertically, subtracting y 3 from
each of the y coordinates (in case you were wondering whether the trapezoid
summing trick works if some of the triangle extends below the x-axis, this
shifting properly shows that it does):
A = y 1 (x 2 − x 3 ) + y 2 (x 3 − x 1 ) + y 3 (x 1 − x 2 )
2
= (y 1 − y 3 )(x 2 − x 3 ) + (y 2 − y 3 )(x 3 − x 1 ) + (y 3 − y 3 )(x 1 − x 2 )
2
= (y 1 − y 3 )(x 2 − x 3 ) + (y 2 − y 3 )(x 3 − x 1 )
2
Computing the area of a
2D triangle from the
coordinates of the
vertices
(9.15)
.
Search WWH ::




Custom Search