def nearestPoint(a, b, c):
 magnitude = np.linalg.norm((b - a))
 if (magnitude == 0):
  raise Exception, 'Line segment cannot be 0 length'
 return (((b - a) * np.dot(((c - a) / magnitude), ((b - a) / magnitude))) + a)

def nearestPoint ( a , b , c ) : magnitude = np . linalg . norm ( ( b - a ) ) if ( magnitude == 0 ) : raise Exception , 'Line segment cannot be 0 length' return ( ( ( b - a ) * np . dot ( ( ( c - a ) / magnitude ) , ( ( b - a ) / magnitude ) ) ) + a )
nearest point to point c on line a_b .