ClosestLineSegmentPoints
From Solid Graphics Wiki

The ClosestLineSegmentPoints function calculates positions and coordinates of closest points of two line segments.
void ClosestLineSegmentPoints ( const float P0[ 3 ], const float P1[ 3 ], const float Q0[ 3 ], const float Q1[ 3 ], float* s, float* t = NULL, bool* parallel = NULL );
void ClosestLineSegmentPoints ( const double P0[ 3 ], const double P1[ 3 ], const double Q0[ 3 ], const double Q1[ 3 ], double* s, double* t = NULL, bool* parallel = NULL );
Parameters
P0  x,y,z coordinates of first point defining the first line segment 
P1  x,y,z coordinates of second point defining the first line segment 
Q0  x,y,z coordinates of first point defining the second line segment 
Q1  x,y,z coordinates of second point defining the second line segment 
s  the function will store the position of closest point on lying on the first line segment into the variable pointed by s. The position can be then translated to point coordinates using the LinePositionToPoint function. 
t  if the parameter is not NULL then the function will store into the variable pointed by t position of the closest point lying on the second line segment. 
parallel  if the parameter is not NULL then the function will set to true variable pointed by the parrallel if the line segments are parallel to each other, or to false when they are not parallel. 
See Also