代码改变世界

AutoLISP绘制矩形和五个圆在其内部相切

2011-03-28 17:52  精诚所至 金石为开  阅读(542)  评论(0编辑  收藏  举报

AutoLISP绘制矩形和五个圆在其内部相切,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq oldlay (getvar "clayer"))
  (setq os (getvar "osmode"))
  (setvar "osmode" 0)
  (setq w (getreal "输入底部宽度<100>:"))
  (setq rp1 (getpoint "\n输入左下角点:"))
  (if (null w) (setq w 100))
  (setq r (/ w 2 (1+ (sqrt 3))))
  (setq cp1 (polar rp1 (/ pi 4) (* r (sqrt 2))))
  (setq cp2 (polar cp1 (/ pi 6) (* r 2)))
  (setq rp2 (polar rp1 0 w))
  (setq rp3 (polar rp2 (/ pi 2) (* 4 r)))
  (setq gap (* 2 (sqrt 3) r))
  (command "-layer" "m" "str" "c" 4 "" "")
  (command "rectang" rp1 rp3)
  (command "circle" cp1 r)
  (command "array" (entlast) "" "r" 2 2 (* r 2) gap)
  (command "circle" cp2 r)
  (command "-layer" "m" "dim" "c" 1 "" "")
  (command "dim1" "hor" rp1 rp2 (polar rp1 (* pi 1.5) 10) "")
  (setvar "osmode" os)
  (setvar "clayer" oldlay)
  (prin1)
  )

代码完。