本帖最后由 LLXXZZ 于 2011-9-6 12:39 编辑
- ;李晓卓于2010年7月8日写此程序,
- ;根据5个点画出四边形,
- ;定义平方子程序
- (defun sqr(xx) (* xx xx))
- ;主程序开始
- (defun C:sbx ( / p1 p2 p3 p4 a1 a2 an1 an2 d1 d2)
- (setvar "CMDECHO" 0)
- (setq OSM (Getvar "OSMODE" ))
- (setq BPM (Getvar "blipmode"))
- (command "ucs" "w" )
- (princ ">>>画出四边形程序正在运行...\n")
- (setq p1 (getpoint"点取四边形左下角点p1: "))
- (setq w1 (getdist p1 "指定四边形右下角点p2到p1的距离<W2>: "))
- (setq d1 (getdist "指定四边形左上角点p4到p2的距离<L2>: "))
- (setq w4 (getdist "指定四边形左上角点p4到p1的距离<H1>: "))
- (setq w2 (getdist "指定四边形右上角点p3到p2的距离<H2>: "))
- (setq d2 (getdist "指定四边形右上角点p3到p1的距离<L1>: "))
- ;用余弦定理计算角度
- (setq a1 (/ (- (+ (sqr w4) (sqr w1)) (sqr d1)) w1 w4 2) )
- (setq b1 (sqrt (- 1 (sqr a1))))
- (setq an1 (atan (/ b1 a1)))
- (if (< an1 0) (setq an1 (+ pi an1)))
- (setq a2 (/ (- (+ (sqr d2) (sqr w1)) (sqr w2)) d2 w1 2) )
- (setq b2 (sqrt (- 1 (sqr a2))))
- (setq an2 (atan (/ b2 a2)))
- (if (< an2 0) (setq an1 (+ pi an2)))
- ;计算端点
- (setq p2 (polar p1 0 w1))
- (setq p4 (polar p1 an1 w4))
- (setq p3 (polar p1 an2 d2))
- ;开始绘制四边形
- (command "PLINE" p1 p2 p3 p4 "c" )
- (setvar "OSMODE" OSM)
- (setvar "blipmode" BPM)
- (command "ucs" "p" )
- (princ ">>>四边形绘制完毕,请自行检查p3到p4<W1>的距离!\n")
- (princ)
- ) ;;;end of defun
- (princ "\n 画四边形.lsp已加载 绘制四边形程序,以sbx启动命令.----by 李晓卓<2010.7.10>")
- (princ)
|