private double computeTriangleArea3D ( DelaunayTriangle triangle ) { TriangulationPoint [ ] points = triangle . points ; TriangulationPoint p1 = points [ 0 ] ; TriangulationPoint p2 = points [ 1 ] ; TriangulationPoint p3 = points [ 2 ] ; /** * 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 = p2 . getX ( ) - p1 . getX ( ) ; double uy = p2 . getY ( ) - p1 . getY ( ) ; double uz = p2 . getZ ( ) - p1 . getZ ( ) ; double vx = p3 . getX ( ) - p1 . getX ( ) ; double vy = p3 . getY ( ) - p1 . getY ( ) ; double vz = p3 . getZ ( ) - p1 . getZ ( ) ; if ( Double . isNaN ( uz ) || Double . isNaN ( vz ) ) { uz = 1 ; vz = 1 ; } // 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 ; return Math . sqrt ( absSq ) / 2 ; }
Computes the 3D area of a triangle .