Re: [問題] 請問AutoCAD中要怎麼畫歪斜線的公垂線??

看板Cad_Cae (電腦輔助設計)作者 (sjgau)時間14年前 (2010/06/20 22:04), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
以下的 AUTOCAD AUTOLISP 程式, 可以自動的做出 三度空間的 一組歪斜線的 公垂線。 這條公垂線的 3D長度,就是這組歪斜線的 最短距離。 使用的方法是,將以下的程式, 存成一個文字檔案, FILE NAME: LSQ.LSP 在 AUTOCAD 指令列輸入 (LOAD "LSQ.LSP") 就可以幫 AUTOCAD 增加一個指令 LSQ 執行這個指令,點選這組歪斜線的兩條線, 即會 自動的做出 公垂線 ; FILE BEGIN HERE ; LSQ.LSP - "LINE SKEW" Connects SKEW lines with the shortest connector ; From original code (c)1992, Mitchell A. Wawzonek ; Mitchell A. Wawzonek, P.Eng., Professor ; School of Engineering Technology ; Conestoga College ; 299 Doon Valley Drive ; Kitchener, ON N2G 4M4 ; Canada ; ; FINDS THE COMMON PERPENDICULAR ; BETWEEN 2 SKEW LINES ; ; 5-26-06 Added error handling and useability in any UCS. ; Also declared local variables. ; (defun lsq_error (msg) (setq *error* sys_error) (command "UCS" "R" "SYSUCS") (command "UCS" "D" "SYSUCS") (setvar "OSMODE" OLDSNAP) (setvar "CMDECHO" 1) (redraw) (princ) ) (defun C:LSQ (/ E1 E2 P1 P2 P3 P4 X1 X2 X3 X4 Y1 Y2 Y3 Y4 Z1 Z2 Z3 Z4 A D B C F CA SA ANG R1 R P5 P6 DS ) (setq sys_error *error*) (setq *error* lsq_error) (setvar "CMDECHO" 0) (setq OLDSNAP (getvar "OSMODE")) (setvar "OSMODE" 0) (command "UCS" "S" "SYSUCS") (command "UCS" "") (setq E1 nil E2 nil) (while (null E1) (setq E1 (entsel "\nLine 1:")) (if E1 (progn (setq E1 (car E1)) (redraw E1 3) (if (/= (cdr (assoc 0 (entget E1))) "LINE") (progn (prompt "\nEntity is a ") (princ (cdr (assoc 0 (entget E1)))) (princ ". Select a LINE") (setq E1 nil) ) ) ) ) ) ;endwhile (while (null E2) (setq E2 (entsel "\nLine 2:")) (if E2 (progn (setq E2 (car E2)) (if (/= (cdr (assoc 0 (entget E2))) "LINE") (progn (prompt "\nEntity is a ") (princ (cdr (assoc 0 (entget E2)))) (princ ". Select a LINE") (setq E2 nil) ) ) ) ) ) ;endwhile (setq P1 (cdr (assoc 10 (entget E1)))) ; start point line 1 (setq P2 (cdr (assoc 11 (entget E1)))) ; end point line 1 (setq P3 (cdr (assoc 10 (entget E2)))) ; start point line 2 (setq P4 (cdr (assoc 11 (entget E2)))) ; end point line 2 (setq X1 (car P1) Y1 (cadr P1) Z1 (caddr P1)) ; components of P1 (setq X2 (car P2) Y2 (cadr P2) Z2 (caddr P2)) ; " " " P2 (setq X3 (car P3) Y3 (cadr P3) Z3 (caddr P3)) ; " " " P3 (setq X4 (car P4) Y4 (cadr P4) Z4 (caddr P4)) ; " " " P4 (setq A (+ (* (- X2 X1)(- X1 X3)) (* (- Y2 Y1)(- Y1 Y3)) (* (- Z2 Z1)(- Z1 Z3)))) (setq D (+ (* (- X4 X3)(- X1 X3)) (* (- Y4 Y3)(- Y1 Y3)) (* (- Z4 Z3)(- Z1 Z3)))) (setq B (+ (* (- X2 X1)(- X2 X1)) (* (- Y2 Y1)(- Y2 Y1)) (* (- Z2 Z1)(- Z2 Z1)))) (setq C (+ (* (- X2 X1)(- X4 X3)) (* (- Y2 Y1)(- Y4 Y3)) (* (- Z2 Z1)(- Z4 Z3)))) (setq F (+ (* (- X4 X3)(- X4 X3)) (* (- Y4 Y3)(- Y4 Y3)) (* (- Z4 Z3)(- Z4 Z3)))) (setq CA (ABS (/ C (* (SQRT B)(SQRT F))))) ;Cosine CA=1 (setq SA (SQRT (ABS (- 1 (* CA CA))))) ;Sine SA=0 (setq ANG (ATAN SA CA)) (princ (strcat "\nAngle = " (angtos ANG 0 4))) (IF (< ANG 0.000005) (princ "\nLines are parallel - No connector\n") (progn (setq R1 (/ (- (* A C) (* B D)) (- (* C C) (* B F)))) (setq R (/ (- (* C R1) A) B)) ; connector end pnts (setq P5 (LIST (+ X1 (* (- X2 X1) R))(+ Y1 (* (- Y2 Y1) R))(+ Z1 (* (- Z2 Z1) R)))) (setq P6 (LIST (+ X3 (* (- X4 X3) R1))(+ Y3 (* (- Y4 Y3) R1))(+ Z3 (* (- Z4 Z3) R1)))) (setq DS (distance P5 P6)) ; connector length (if (or (< 1 R) (< 1 R1)) (princ " * * * CAUTION: Connector past end of Line 1 or 2")) (if (or (< R 0) (< R1 0)) (princ " * * * CAUTION: Connector past end of Line 1 or 2")) (princ (strcat "\nConnector length = " (rtos DS))) (if (> DS 0.00000000001) (command ".LINE" P5 P6 "") (princ "\nLines intersect - no connection") ) );endprogn );endif (setq *error* sys_error) (command "UCS" "R" "SYSUCS") (command "UCS" "D" "SYSUCS") (setvar "OSMODE" OLDSNAP) (setvar "CMDECHO" 1) (princ "\r") (redraw) (princ) ) ; END OF FILE ※ 引述《sjgau (sjgau)》之銘言: : 留言主題:如何作投影 : 留言人:sjgau 回覆 刪除 : 首先要確定 UCS 的xy- 平面 : 以經設定到 相交的 兩根直線上面 : 接著從第一條直線的兩個端點, : 把兩個端點,投影到 這個平面上。 : 所謂的投影,是針對當時的UCS : 投影點的 x, y 座標和原來的點相同, : z- 座標的值等於 0 : 2005-10-02 12:23:16 --59.104.49.139-- : 留言主題:要怎麼投影 : 留言人:seapighead 回覆 刪除 : 歪斜線作公垂線中 : 要用什麼指令把LINE-1投影到XY平面 : ※ 引述《seapighead (豬頭)》之銘言: : : 空間中的一對歪斜線 : : 要怎麼畫出兩線的公垂線 : : 請高手教一下 : : 急著想知道 : : 幫幫忙 : : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.140.33.205
文章代碼(AID): #1C7X_yJ_ (Cad_Cae)
文章代碼(AID): #1C7X_yJ_ (Cad_Cae)