Given three vertices in 3-D space — (x1, y1, z1), (x2, y2, z2), and (x3, y3, z3) — there are two common approaches to computing the area of the triangle they define.
Heron's Formula
First, compute the lengths of the three sides:
b = √[ (x1 − x3)2 + (y1 − y3)2 + (z1 − z3)2 ]
c = √[ (x2 − x3)2 + (y2 − y3)2 + (z2 − z3)2 ]
Then compute the semiperimeter:
And plug everything into Heron's formula:
Considerations
-
If the triangle is a very thin sliver (nearly degenerate), Heron's formula
can suffer from floating-point cancellation errors. A numerically stable
variant exists: sort the sides so that a ≥ b ≥
c, then use
Area = ¼ √[ (a+(b+c)) · (c−(a−b)) · (c+(a−b)) · (a+(b−c)) ] - This approach requires four square roots — one for each side and one in the final formula. If you need to compute thousands of triangle areas and have no other use for the side lengths, the cross-product method below is more efficient.
Cross-Product Method
The area of a triangle is half the magnitude of the cross product of two edge vectors. If we define the vectors u and v as two edges sharing a common vertex:
v = (x3 − x1, y3 − y1, z3 − z1)
The cross product u × v has three components:
ny = uz · vx − ux · vz
nz = ux · vy − uy · vx
And the area is:
Expanded Form
Substituting the vertex coordinates directly, the formula expands to a single expression. This is long but easy for a computer, and it requires only one square root:
ny = (z2−z1)(x3−x1) − (x2−x1)(z3−z1)
nz = (x2−x1)(y3−y1) − (y2−y1)(x3−x1)
Area = √( nx2 + ny2 + nz2 ) / 2
This is the approach to prefer when performance matters — it involves only multiplications, additions, subtractions, and a single square root. It is also numerically stable for thin slivers, unlike the naive form of Heron's formula.