private void accumulateNormal ( final Element center , final Element pre , final Element post ) { double cx = center . getDouble ( "x" ) ; double cy = center . getDouble ( "y" ) ; double cz = center . getDouble ( "z" ) ; double ax = post . getDouble ( "x" ) - cx ; double ay = post . getDouble ( "y" ) - cy ; double az = post . getDouble ( "z" ) - cz ; double a = Math . sqrt ( ax * ax + ay * ay + az * az ) ; if ( a < EPSILON ) { return ; } double bx = pre . getDouble ( "x" ) - cx ; double by = pre . getDouble ( "y" ) - cy ; double bz = pre . getDouble ( "z" ) - cz ; double b = Math . sqrt ( bx * bx + by * by + bz * bz ) ; if ( b < EPSILON ) { return ; } double nx = ay * bz - az * by ; double ny = az * bx - ax * bz ; double nz = ax * by - ay * bx ; double n = Math . sqrt ( nx * nx + ny * ny + nz * nz ) ; if ( n < EPSILON ) { return ; } double sin = n / ( a * b ) ; double dot = ax * bx + ay * by + az * bz ; double angle ; if ( dot < 0 ) { angle = Math . PI - Math . asin ( sin ) ; } else { angle = Math . asin ( sin ) ; } double factor = angle / n ; nx *= factor ; ny *= factor ; nz *= factor ; center . setDouble ( "nx" , center . getDouble ( "nx" ) + nx ) ; center . setDouble ( "ny" , center . getDouble ( "ny" ) + ny ) ; center . setDouble ( "nz" , center . getDouble ( "nz" ) + nz ) ; }
Calculate the face normal weight by angle and add them to the vertex .