main/src/georegression/metric/ClosestPoint3D_F64.java
public static Point3D_F64 closestPoint(LineParametric3D_F64 line, Point3D_F64 pt, Point3D_F64 ret)
	{
		if( ret == null ) {
			ret = new Point3D_F64();
		}

		double dx = pt.x - line.p.x;
		double dy = pt.y - line.p.y;
		double dz = pt.z - line.p.z;

		double n2 = line.slope.normSq();

		double d = (line.slope.x*dx + line.slope.y*dy + line.slope.z*dz);

		ret.x = line.p.x + d * line.slope.x / n2;
		ret.y = line.p.y + d * line.slope.y / n2;
		ret.z = line.p.z + d * line.slope.z / n2;

		return ret;
	}
public static Point3D_F64 closestPoint(LineParametric3D_F64 line, Point3D_F64 pt, Point3D_F64 ret)
	{
		if( ret == null ) {
			ret = new Point3D_F64();
		}

		double dx = pt.x - line.p.x;
		double dy = pt.y - line.p.y;
		double dz = pt.z - line.p.z;

		double n2 = line.slope.normSq();

		double d = (line.slope.x*dx + line.slope.y*dy + line.slope.z*dz);

		ret.x = line.p.x + d * line.slope.x / n2;
		ret.y = line.p.y + d * line.slope.y / n2;
		ret.z = line.p.z + d * line.slope.z / n2;

		return ret;
	}
Finds the closest point on a line to the specified point.

@param line Line on which the closest point is being found.  Not modified.
@param pt   The point whose closest point is being looked for.  Not modified.
@param ret  Storage for the solution.  Can be same as instance as 'pt'. If null is passed in a new point is created. Modified.