main/src/georegression/metric/ClosestPoint2D_F64.java
public static Point2D_F64 closestPoint( LineGeneral2D_F64 line,
											Point2D_F64 p,
											Point2D_F64 output ) {
		if( output == null )
			output = new Point2D_F64();

		double AA = line.A*line.A;
		double AB = line.A*line.B;
		double BB = line.B*line.B;

		output.y = AA*p.y - AB*p.x - line.B*line.C;
		output.y /= AA+BB;

		output.x = BB*p.x - AB*p.y - line.A*line.C;
		output.x /= AA+BB;

		return output;
	}
public static Point2D_F64 closestPoint( LineGeneral2D_F64 line,
											Point2D_F64 p,
											Point2D_F64 output ) {
		if( output == null )
			output = new Point2D_F64();

		double AA = line.A*line.A;
		double AB = line.A*line.B;
		double BB = line.B*line.B;

		output.y = AA*p.y - AB*p.x - line.B*line.C;
		output.y /= AA+BB;

		output.x = BB*p.x - AB*p.y - line.A*line.C;
		output.x /= AA+BB;

		return output;
	}
public static Point2D_F64 closestPoint ( LineGeneral2D_F64 line , Point2D_F64 p , Point2D_F64 output ) { if ( output == null ) output = new Point2D_F64 ( ) ; double AA = line . A * line . A ; double AB = line . A * line . B ; double BB = line . B * line . B ; output . y = AA * p . y - AB * p . x - line . B * line . C ; output . y /= AA + BB ; output . x = BB * p . x - AB * p . y - line . A * line . C ; output . x /= AA + BB ; return output ; }
<p>
Finds the closest point on 'line' to the specified point.
</p>

@param line Line along which the closest point is to be found.
@param p Point.
@param output Where the solution is stored.  If null a new instance is created. Modified.
@return Closest point on the line.
<p > Finds the closest point on line to the specified point . < / p >