rem D_PtLn.cdl rem Copy Right by International Technology Transfer Corp. rem revision 1.0 7/30/99 rem ******************************************************************** rem Distance between Point and Line rem ******************************************************************** clear defopt = 2 :start getpos "Indicate Point",defopt on (@key + 3) goto exit,start,start, defopt=@key x0 = @xworld y0 = @yworld z0 = @zworld :line getent "Select Line",enttype on (@key + 3) goto exit, start, line, if (enttype!=2) goto line x1 = @fltdat[0] y1 = @fltdat[1] z1 = @fltdat[2] x2 = @fltdat[3] y2 = @fltdat[4] z2 = @fltdat[5] f = x2 - x1 g = y2 - y1 h = z2 - z1 rem Refer to L_PtLn.cdl rem *********************************************************************** t = (f * (x0 - x1) + g * (y0 - y1) + h * (z0 - z1)) / (f*f + g*g + h*h) x = x1 + f * t y = y1 + g * t z = z1 + h * t mode draw line x0, y0, z0, x, y, z, 15,,2 mode normal dist=sqrt((x-x0)*(x-x0)+(y-y0)*(y-y0)+(z-z0)*(z-z0)) pause " Distance between Point and Line = %.3f", dist redraw goto start :exit