本帖最后由 荒野孤行 于 2015-5-24 21:54 编辑
想起刚开始学AutoCAD的时候,都是画的一些有数学关系的图,那时有很多图形都没画出来。现在用lisp写出来,感觉so easy!
源码如下:
- ;;;*****矩形4圆相切 程序开始*****
- (defun c:t1 ()
- (setvar "cmdecho" 0)
- (setvar "osmode" 15359)
- (princ "\n功能:通过矩形绘制出与其四边相切,且四圆两两相切的圆.")
- (initget 7)
- (setq l_len (getdist "\n请输入矩形的长度:"))
- (initget 7)
- (setq l_wid (getdist "\n请输入矩形的宽度:"))
- (initget 3)
- (setq pt1 (getpoint "\n请指定插入点:"))
- (setvar "osmode" 0)
- (setq L1 (* l_wid 0.5))
- (setq L2 (* l_len 0.5))
- (setq a (* 2.0 L1))
- (setq b (+ (* L2 L2) (* L1 L1 -1.0) (* 4.0 L1 L2)))
- (setq c (* 2.0 L1 L1 L2))
- (setq r2 (/ (+ b (sqrt (+ (* b b) (* 4.0 a c)))) (* 2.0 a) 1.0))
- (setq r1 (+ (/ (* L1 L1) r2 1.0) (* 2.0 L1)))
- (setq pt2 (polar pt1 0 l_len))
- (setq pt12 (polar pt1 0 (* l_len 0.5)))
- (setq pt_r2 (polar pt12 (angtof "90") r2))
- (setq pt3 (polar pt2 (angtof "-90") l_wid))
- (setq pt4 (polar pt1 (angtof "-90") l_wid))
- (setq pt34 (polar pt1 (angtof "-90") (* l_wid 0.5)))
- (setq pt_r1 (polar pt34 (angtof "180") r1))
- (command "color" 1)
- (command "PLINE" pt1 pt2 pt3 pt4 "c")
- (command "color" 3)
- (command "CIRCLE" pt_r2 r2)
- (command "MIRROR" (entlast) "" pt34 pt_r1 "")
- (command "color" 4)
- (command "CIRCLE" pt_r1 r1)
- (command "MIRROR" (entlast) "" pt12 pt_r2 "")
- (command "color" "Bylayer")
- (setvar "osmode" 15359)
- (princ)
- )
- ;;;*****矩形4圆相切 程序结束*****
|