@ Unefficient public static void computeClosestPointTrianglePoint ( double tx1 , double ty1 , double tz1 , double tx2 , double ty2 , double tz2 , double tx3 , double ty3 , double tz3 , double px , double py , double pz , Point3D closestPoint ) { if ( containsTrianglePoint ( tx1 , ty1 , tz1 , tx2 , ty2 , tz2 , tx3 , ty3 , tz3 , px , py , pz , false , MathConstants . EPSILON ) ) { closestPoint . set ( toPlane ( tx1 , ty1 , tz1 , tx2 , ty2 , tz2 , tx3 , ty3 , tz3 ) . getProjection ( px , py , pz ) ) ; return ; } double f ; f = AbstractSegment3F . getPointProjectionFactorOnSegmentLine ( px , py , pz , tx1 , ty1 , tz1 , tx2 , ty2 , tz2 ) ; double p1x = tx1 + f * ( tx2 - tx1 ) ; double p1y = ty1 + f * ( ty2 - ty1 ) ; double p1z = tz1 + f * ( tz2 - tz1 ) ; f = AbstractSegment3F . getPointProjectionFactorOnSegmentLine ( px , py , pz , tx2 , ty2 , tz2 , tx3 , ty3 , tz3 ) ; double p2x = tx2 + f * ( tx3 - tx2 ) ; double p2y = ty2 + f * ( ty3 - ty2 ) ; double p2z = tz2 + f * ( tz3 - tz2 ) ; f = AbstractSegment3F . getPointProjectionFactorOnSegmentLine ( px , py , pz , tx3 , ty3 , tz3 , tx1 , ty1 , tz1 ) ; double p3x = tx3 + f * ( tx1 - tx3 ) ; double p3y = ty3 + f * ( ty1 - ty3 ) ; double p3z = tz3 + f * ( tz1 - tz3 ) ; double d1 = FunctionalPoint3D . distanceSquaredPointPoint ( px , py , pz , p1x , p1y , p1z ) ; double d2 = FunctionalPoint3D . distanceSquaredPointPoint ( px , py , pz , p2x , p2y , p3z ) ; double d3 = FunctionalPoint3D . distanceSquaredPointPoint ( px , py , pz , p3x , p3y , p3z ) ; if ( d1 <= d2 ) { if ( d1 <= d3 ) { closestPoint . set ( p1x , p1y , p1z ) ; } else { closestPoint . set ( p3x , p3y , p3z ) ; } } if ( d2 <= d3 ) { closestPoint . set ( p2x , p2y , p2z ) ; } else { closestPoint . set ( p3x , p3y , p3z ) ; } }
Replies the closest point from the triangle to the point .