rem L_PtLn.cdl rem Copy Right by International Technology Transfer Corp. rem revision 1.0-7/30/99 rem ******************************************************************** rem Line from Point perpendicular to specified line rem 1. Indicate Point rem 2. Select Line rem 3. Draw the perpendicular 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 *********************************************************************** rem equation for space rem x = x1 + f * t rem y = y1 + g * t rem z = z1 + h * t rem rem i x1 + f * tAy1 + g * tAz1 + h * tj rem calculate t to minimize l below rem l*l = (x1 + f*t - x0)*(x1 + f*t - x0) rem + (y1 + g*t - y0)*(y1 + g*t - y0) + (z1 + h*t - z0)*(z1 + h*t - z0) rem when t = t0, minimum rem ( t0 = (f * (x0-x1) + g * (y0-y1) + h * (z0-z1)) / (f*f + g*g + h*h) ) 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 line x0, y0, z0, x, y, z redraw goto start :exit