代码改变世界

AutoCAD LISP绘制环形图案

2011-03-27 15:22  精诚所至 金石为开  阅读(334)  评论(0编辑  收藏  举报

AutoCAD LISP绘制由正三角形和圆形组成的环形图案,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq pt1 (getpoint "\n第一点:"))
  (setq pt2 (getpoint pt1 "\n第二点:"))
  (setq ll (distance pt1 pt2))
  (setq ang (angle pt1 pt2))
  (setq pt3 (polar pt2 (+ ang (/ (* 120 pi) 180)) ll))
  (command "polygon" 3 "e" pt1 pt2)
  (command "arc" pt1 "e" pt2 "a" 180)
  (setq en1 (entlast))
  (setq mid1 (polar pt1 ang (/ ll 2)))
  (command "circle" "2p" mid1 (polar mid1 (+ ang (* pi 1.5)) (/ ll 2)))
  (setq en2 (entlast))
  (setq mid2 (polar pt2 (+ ang (/ (* 120 pi) 180)) (/ ll 2)))
  (setq cen (inters pt3 mid1 pt1 mid2))
  (command "array" en1 en2 "" "P" cen 3 "" "")
  (prin1)
  )

代码完。