您的位置:网站首页 > CAD新闻

AutoLISP矩形与多个内切圆

时间:2011-08-14 16:27:44 来源:未知

AutoLISP矩形与多个内切圆

AutoLISP矩形与多个内切圆,代码如下。

(defun c:test()
  (setvar "cmdecho" 0)
  (setq oldlay (getvar "clayer"))
  (setq oldosmode (getvar "osmode"))
  (setvar "osmode" 0)
  (setq w (getreal "输入底部宽度<100>:"))
  (setq n (getint "n几排垂直圆<2>:"))
  (setq rp1 (getpoint "n输入左下角点:"))
  (if (null w) (setq w 100))
  (if (null n) (setq n 2))
  (setq r (/ w 2 (1+ (* (sqrt 3) (1- n)))))
  (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 n (* r 2) gap)
  (command "circle" cp2 r)
  (if (> n 2) (command "array" (entlast) "" "r" 1 (1- n) gap))
  (command "-layer" "m" "dim" "c" 1 "" "")
  (command "dim1" "hor" rp1 rp2 (polar rp1 (* pi 1.5) 10) "")
  (setvar "somode" oldosmode)
  (setvar "clayer" oldlay)
  )

代码完。