FUNCTION distance_point_to_line,A,B,C,P=u ;+ ;d=distance_point_to_line(A,B,C) finds the ;Euclidean distance from a line described by two ;points A and B to a point C. All of the points ;are n-dimensional vectors, where n>1. If A=B then ;the distance between two points A and C is measured. ; ;KEYWORD ;D=distance_point_to_line(A,B,C,P=u) ;returns the point P on the line closest to the point C. ; ;H. Rhody ;July, 2004 ;- IF Min([n_elements(A),n_elements(B),n_elements(C)]) LT 2 THEN $ MESSAGE,'Vectors must be at least 2D' IF MAX(A NE B) EQ 0 THEN BEGIN $ ;A=B case u=A return,sqrt(inprod(A-C,A-C)) ENDIF v=C-A w=B-A t=inprod(v,w)/inprod(w,w) u=A+t*w return,sqrt(inprod(u-C,u-C)) END