Lisp lệnh ARL ACL ACL1 trong chủ đề “Hỏi về cách vẽ 1 cung có kích thước chính xác.”
Hề hề hề,
Đây là code của bác SSG mình sửa lại chút chút theo yêu cầu của bạn. Lệnh vẽ là acl1 khác chút chút với lệnh acl của bác SSG. Ưu nhược điểm của nó thì bạn đọc các bài post phía trên sẽ hiểu.
- Tải lisp
- 194024_arl_acl_acl1.lsp
Cách dùng
- Tải tệp 194024_arl_acl_acl1.lsp về máy.
- Trong AutoCAD gõ lệnh APPLOAD, chọn tệp vừa tải rồi bấm Load. Cũng có thể kéo thả tệp .lsp vào cửa sổ bản vẽ.
- Gõ lệnh ARL ACL ACL1 để chạy lisp.
Mã nguồn 194024_arl_acl_acl1.lsp
;; free lisp from cadviet.com
;;; this lisp was downloaded from https://www.cadviet.com/forum/topic/3689-h%E1%BB%8Fi-v%E1%BB%81-c%C3%A1ch-v%E1%BA%BD-1-cung-c%C3%B3-k%C3%ADch-th%C6%B0%E1%BB%9Bc-ch%C3%ADnh-x%C3%A1c/
;;;-----------------------------------------------------------
(defun RTD(x) (/ (* x 180) pi) )
;;;-----------------------------------------------------------
(defun Tang(x) (/ (sin x) (cos x)) )
;;;-----------------------------------------------------------
(defun asin(x)
(cond
((and (< x 1) (> x -1)) (atan (/ x (sqrt (- 1 (expt x 2))))) )
((= x 1) (/ pi 2))
((= x -1) (/ pi -2))
)
)
;;;-----------------------------------------------------------
(defun acos(x) (- (/ pi 2) (asin x)))
;;;-----------------------------------------------------------
(defun C:ARL( / R L p1 p2 a oldos) ;;;Arc with Radius + Length
(setq
R (getreal "\nBan kinh:")
L (getreal "\nChieu dai cung:")
p1 (getpoint "\nDiem chuan:")
p2 (polar p1 pi R)
a (rtd (/ L R))
oldos (getvar "osmode")
)
(setvar "osmode" 0)
(command "arc" p1 "c" p2 "a" a)
(setvar "osmode" oldos)
(princ)
)
;;;-----------------------------------------------------------
(defun C:ACL(/ C L p1 p2 x dx h p3 oldos) ;;;Arc with Chord + Length
(setq
C (getreal "\nChieu dai day:")
L (getreal "\nChieu dai cung:")
)
(if (>= C L) (progn (alert "Error! Chieu dai day phai nho hon chieu dai cung!") (exit)))
(setq
p1 (getpoint "\nDiem chuan:")
p2 (polar p1 pi C)
x (* 2 (acos (/ C L)))
dx 0.00001
)
(while (> (/ x (sin x)) (/ L C)) (setq x (- x dx)))
(setq dx (* dx dx))
(if (/= (/ x (sin x)) (/ L C))
(while (< (/ x (sin x)) (/ L C)) (setq x (+ x dx)))
)
(setq
x (- x (/ dx 2))
h (* (/ C 2) (tang (/ x 2)))
p3 (list (- (car p1) (/ C 2)) (+ (cadr p1) h))
oldos (getvar "osmode")
)
(setvar "osmode" 0)
(command "arc" p1 p3 p2)
(setvar "osmode" oldos)
(princ)
)
;;;-----------------------------------------------------------
(defun C:ACL1(/ C L p1 p2 x dx h p3 oldos) ;;;Arc with Chord + Length
(setq
p1 (getpoint "\nDiem neo thu nhat:")
p2 (getpoint p1 "\n Diem neo thu hai")
)
(setq
C (distance p1 p2)
L (getreal "\nChieu dai cung:")
x (* 2 (acos (/ C L)))
dx 0.00001
ang (angle p1 p2)
pm (list (/ (+(car p2) (car p1)) 2) (/ (+ (cadr p2) (cadr p1)) 2))
)
(if (>= C L) (progn (alert "Error! Chieu dai day phai nho hon chieu dai cung!") (exit)))
(while (> (/ x (sin x)) (/ L C)) (setq x (- x dx)))
(setq dx (* dx dx))
(if (/= (/ x (sin x)) (/ L C))
(while (< (/ x (sin x)) (/ L C)) (setq x (+ x dx)))
)
(setq
x (- x (/ dx 2))
h (* (/ C 2) (tang (/ x 2)))
p3 (list (- (car pm) (* h (sin ang))) (+ (cadr pm) (* h (cos ang))))
oldos (getvar "osmode")
)
(setvar "osmode" 0)
(command "arc" p1 p3 p2)
(setvar "osmode" oldos)
(princ)
)
Thảo luận gốc
Lisp được chia sẻ trong chủ đề Hỏi về cách vẽ 1 cung có kích thước chính xác.. Xem đúng bài viết #194024 để đọc hướng dẫn và trao đổi thêm.