Fucntion to compute nearest point on line
First version of random track generator
nearestPoint() now handles zero length lines