public static double distance ( LineParametric3D_F64 l , Point3D_F64 p ) { double x = l . p . x - p . x ; double y = l . p . y - p . y ; double z = l . p . z - p . z ; double cc = x * x + y * y + z * z ; // could avoid a square root here by computing b*b directly // however that is most likely more prone to numerical overflow since the numerator will need to be squared // before division can reduce its "power" double b = MiscOps . dot ( x , y , z , l . slope ) / l . slope . norm ( ) ; double distanceSq = cc - b * b ; // round off error can make distanceSq go negative when it is very close to zero if ( distanceSq < 0 ) { return 0 ; } else { return Math . sqrt ( distanceSq ) ; } }
Distance from the point to the closest point on the line .