isalan 发表于 2012-4-18 22:41:02

麻烦能帮我看一下,这段代码是哪里有问题吗?

;;;基准点p1为r1的圆心
(defun c:tj1()
(setq os (getvar "osmode"))

(setvar "osmode" 0)

(setq r1 (getreal "\n 请输入第一半径 r1:"))
(setq r2 (getreal "\n 请输入第二半径 r2:"))
(setq d (getreal "\n 请输入中心厚度 d:"))
(setq dia (getreal "\n 请输入直径 dia:"))
(setq dia1 (getreal "\n 请输入r1面内径(若无,输入:0)dia1:"))
(setq dia2 (getreal "\n 请输入r2面内径(若无,输入:0)dia2:"))
(setq p1 (getpoint "\n 请输入一个基准点(r1圆心) p1:"))

(setq x1 (car p1))
(setq y1 (cadr p1))
(setq x2 (+ d r2 (- x1 r1)))
(setq y2 y1)

(if (= r1 0)
   (setq a1 0)   
   (setq a1 (sqrt (- (expt r1 2) (expt (/ dia 2) 2))))
)

(if (= r1 0)
    (setq x3 x1)
    (if (< r1 0)
(setq x3 (+ x1 a1))
(setq x3 (- x1 a1))
    )
)

   
(if (= r2 0)
   (setq a2 0)
   (setq a2 (sqrt (- (expt r2 2) (expt (/ dia 2) 2))))
)

(if (= r2 0)
   (setq x5 x2)
   (if (< r2 0)
       (setq x5 (+ x2 a2))
       (setq x5 (- x2 a2))
   )
)



(setq x4 x3)
(setq x6 x5)
(setq x7 x3)
(setq x8 x3)
(setq x9 x5)
(setq x10 x5)
(setq y3 (- y1 (/ dia 2)))
(setq y4 (+ y1 (/ dia 2)))
(setq y5 y3)
(setq y6 y4)


(if (= dia1 0)
   (setq y7 y3)   
   (setq y7 (- y1 (/ dia1 2)))
)

(if (= dia1 0)
   (setq y8 y4)   
   (setq y8 (+ y1 (/ dia1 2)))
)


(if (= dia2 0)
   (setq y9 y5)   
   (setq y9 (- y1 (/ dia2 2)))
)

(if (= dia2 0)
   (setq y10 y6)   
   (setq y10 (+ y1 (/ dia2 2)))
)


(setq p2 (list x2 y2))
(setq p3 (list x3 y3))
(setq p4 (list x4 y4))
(setq p5 (list x5 y5))
(setq p6 (list x6 y6))
(setq p7 (list x7 y7))
(setq p8 (list x8 y8))
(setq p9 (list x9 y9))
(setq p10 (list x10 y10))

(command "line" p4 p6 "")
(command "line" p3 p5 "")
(command "line" p3 p7 "")
(command "line" p4 p8 "")
(command "line" p5 p9 "")
(command "line" p6 p10 "")

   
(if (= r1 0)
    (command "line" p7 p8 "")
    (if (< r1 0)
       (command "arc" p7 "ce" p1 p8)
       (command "arc" p8 "ce" p1 p7)
    )
)
(if (= r2 0)
    (command "line" p9 p10 "")
    (if (> r2 0)
      (command "arc" p10 "ce" p2 p9)
      (command "arc" p9 "ce" p2 p10)
    )
)

(setvar "osmode" os)
)
(princ "\n透镜绘制程序")
(princ "\n加载成功!命令行以tj1启动!")
(princ)
页: [1]
查看完整版本: 麻烦能帮我看一下,这段代码是哪里有问题吗?