rem P_2Ln.CDL rem Copy Right by International Technology Transfer Corp. rem revision 1.0-7/30/99 rem Intersection of two Lines clear acc = 0.0001 rem accの値は許容誤差値です :start getent "Select First Line",enttype on (@key + 3) goto exit,start, start, if (enttype!=2) goto start x1 = @fltdat[0] y1 = @fltdat[1] z1 = @fltdat[2] x2 = @fltdat[3] y2 = @fltdat[4] z2 = @fltdat[5] f1 = x2 - x1 g1 = y2 - y1 h1 = z2 - z1 rem *********************************************************************** rem first line rem x = x1 + f1 * t rem y = y1 + g1 * t rem z = z1 + h1 * t rem *********************************************************************** :second getent "Select Second Line",enttype on (@key + 3) goto exit, start, second, if (enttype!=2) goto second x3 = @fltdat[0] y3 = @fltdat[1] z3 = @fltdat[2] x4 = @fltdat[3] y4 = @fltdat[4] z4 = @fltdat[5] f2 = x4 - x3 g2 = y4 - y3 h2 = z4 - z3 rem *********************************************************************** rem 2nd line rem x = x3 + f2 * s rem y = y3 + g2 * s rem z = z3 + h2 * s rem rem x1 + f1 * t = x3 + f2 * s rem y1 + g1 * t = y3 + g2 * s rem z1 + h1 * t = z3 + h2 * s rem Solve t rem *********************************************************************** fg = f1 * g2 - f2 * g1 gh = g1 * h2 - g2 * h1 hf = h1 * f2 - h2 * f1 if (abs(fg)>acc) goto case1 if (abs(gh)>acc) goto case2 if (abs(hf)>acc) goto case3 pause "Line is Parallel" redraw goto start :case1 t = (-f2 * (y3-y1) + g2 * (x3-x1))/fg goto next1 :case2 t = (-g2 * (z3-z1) + h2 * (y3-y1))/gh goto next1 :case3 t = (-h2 * (x3-x1) + f2 * (z3-z1))/hf rem *********************************************************************** rem Dist between Lines rem Dist = abs(bunshi) / bunbo rem rem | x3 - x1 y3 - y1 z3 - z1 | rem bunshi = | f1 g1 h1 | rem | f2 g2 h2 | rem rem bunbo = sqrt(fg*fg + gh*gh + hf*hf) rem rem fg = f1*g2 - f2*g1 , gh = g1*h2 - g2*h1 , hf = h1*f2 - h2*f1 rem *********************************************************************** :next1 bunshi = abs((x3-x1) * gh + (y3-y1) * hf + (z3-z1) * fg) if ( bunshi < acc) goto next2 pause "No Intersection!" redraw goto start :next2 x = x1 + f1 * t y = y1 + g1 * t z = z1 + h1 * t point x, y, z, pause "Intersection Point( %.5f , %.5f , %.5f )", x, y, z redraw goto start :exit