area3DStatic static method
Computes the 3D area of a triangle. The value computed is always non-negative.
@param a a vertex of the triangle @param b a vertex of the triangle @param c a vertex of the triangle @return the 3D area of the triangle
Implementation
static double area3DStatic(Coordinate a, Coordinate b, Coordinate c) {
/**
* Uses the formula 1/2 * | u x v | where u,v are the side vectors of the
* triangle x is the vector cross-product
*/
// side vectors u and v
double ux = b.x - a.x;
double uy = b.y - a.y;
double uz = b.getZ() - a.getZ();
double vx = c.x - a.x;
double vy = c.y - a.y;
double vz = c.getZ() - a.getZ();
// cross-product = u x v
double crossx = uy * vz - uz * vy;
double crossy = uz * vx - ux * vz;
double crossz = ux * vy - uy * vx;
// tri area = 1/2 * | u x v |
double absSq = crossx * crossx + crossy * crossy + crossz * crossz;
double area3D = math.sqrt(absSq) / 2;
return area3D;
}