main/src/georegression/metric/alg/DistancePointTriangle3D_F64.java
public void closestPoint(Point3D_F64 P , Point3D_F64 closestPt ) {

		// D = B-P
		GeometryMath_F64.sub(B, P, D);

		a = E0.dot(E0);
		b = E0.dot(E1);
		c = E1.dot(E1);
		d = E0.dot(D);
		e = E1.dot(D);

		double det = a * c - b * b;
		s = b * e - c * d;
		t = b * d - a * e;

		if (s + t <= det) {
			if (s < 0) {
				if (t < 0) {
					region4();
				} else {
					region3();
				}
			} else if (t < 0) {
				region5();
			} else {
				region0(det);
			}
		} else {
			if (s < 0) {
				region2();
			} else if (t < 0) {
				region6();
			} else {
				region1();
			}
		}

		closestPt.x = B.x + s*E0.x  + t*E1.x;
		closestPt.y = B.y + s*E0.y  + t*E1.y;
		closestPt.z = B.z + s*E0.z  + t*E1.z;
	}
public void closestPoint(Point3D_F64 P , Point3D_F64 closestPt ) {

		// D = B-P
		GeometryMath_F64.sub(B, P, D);

		a = E0.dot(E0);
		b = E0.dot(E1);
		c = E1.dot(E1);
		d = E0.dot(D);
		e = E1.dot(D);

		double det = a * c - b * b;
		s = b * e - c * d;
		t = b * d - a * e;

		if (s + t <= det) {
			if (s < 0) {
				if (t < 0) {
					region4();
				} else {
					region3();
				}
			} else if (t < 0) {
				region5();
			} else {
				region0(det);
			}
		} else {
			if (s < 0) {
				region2();
			} else if (t < 0) {
				region6();
			} else {
				region1();
			}
		}

		closestPt.x = B.x + s*E0.x  + t*E1.x;
		closestPt.y = B.y + s*E0.y  + t*E1.y;
		closestPt.z = B.z + s*E0.z  + t*E1.z;
	}
public void closestPoint ( Point3D_F64 P , Point3D_F64 closestPt ) { // D = B-P GeometryMath_F64 . sub ( B , P , D ) ; a = E0 . dot ( E0 ) ; b = E0 . dot ( E1 ) ; c = E1 . dot ( E1 ) ; d = E0 . dot ( D ) ; e = E1 . dot ( D ) ; double det = a * c - b * b ; s = b * e - c * d ; t = b * d - a * e ; if ( s + t <= det ) { if ( s < 0 ) { if ( t < 0 ) { region4 ( ) ; } else { region3 ( ) ; } } else if ( t < 0 ) { region5 ( ) ; } else { region0 ( det ) ; } } else { if ( s < 0 ) { region2 ( ) ; } else if ( t < 0 ) { region6 ( ) ; } else { region1 ( ) ; } } closestPt . x = B . x + s * E0 . x + t * E1 . x ; closestPt . y = B . y + s * E0 . y + t * E1 . y ; closestPt . z = B . z + s * E0 . z + t * E1 . z ; }
Find the closest point on the triangle to P.
@param P Input.  The point for which the closest point is to be found.
@param closestPt Output.  The found closest point.
Find the closest point on the triangle to P .