point2line
index
 
Name closestPointToLine ( )
Description Finds the closest point on a continuous line from an array of points.
Credits for the algorithm goes to softsurfer.com.
http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm#closest2D_Point_to_Line()
Syntax
closestPointToLine(points, linePointA, linePointB);
Parameters
points   (Vect2[])
linePointA   (Vect2)
linePointB   (Vect2)
Returns index of the closest point to the line (int)
Usage Web & Application
Related
Examples
import point2line.*;

Vect2 linePoint1 = new Vect2( 0, 0 );
Vect2 linePoint2 = new Vect2( 100, 100 );
Vect2[] testPoints = new Vect2[ 100 ];
for( int i=0; i<testPoints.length; i++ ){
  testPoints[ i ] = new Vect2( random( 100 ), random( 100 ) );
}

int closetPointIndex = Space2.closestPointToLine( testPoints, linePoint1, linePoint2 );

println( testPoints[ closetPointIndex ] );