程序如下,作用是自动标出点的方位,方位大概和手表的顺时针差不多。用了cond后,一般没啥问题,但有几次遇到360°无法变0°的情况,是数字换算的误差吗?我现在是用359°的极近值来代替,有什么更好的方法吗?- (defun C:FangWei(/ cir pt0 pt p jd ptx)
- (setq cir (entget (car (entsel "\n选择圆: "))))
- (WYB-entlay "3" 1 "center2");红色
- (setq pt0 (cdr (assoc 10 cir)))
- (setq pt (list (car pt0) (cadr pt0)))
- (while
- (setq p (getpoint "\n选择方位点: "))
- (setq jd (angle p pt))
- (setq ptx (polar p jd -4.5))
- (cond
- ((<= jd (* pi 1.5)) (setq jd (- 270 (WYB-rtod jd))))
- ((> jd (* pi 1.5)) (setq jd (- 630 (WYB-rtod jd))))
- )
- (if (> jd 359.99999999) (setq jd 0))
- (WYB-enttext-all "3" ptx (strcat (rtos jd) "%%d") 3.5 0 "M")
- )
- (princ)
- )
- (defun WYB-rtod(r);弧度换成角度
- (/ (* r 180) pi)
- )
- (defun WYB-enttext-all(tc pt ss hh rr dz / dz1 dz2)
- (cond
- ((= dz "L") (setq dz1 0 dz2 0))
- ((= dz "C") (setq dz1 1 dz2 0))
- ((= dz "R") (setq dz1 2 dz2 0))
- ((= dz "A") (setq dz1 3 dz2 0))
- ((= dz "M") (setq dz1 4 dz2 0))
- ((= dz "F") (setq dz1 5 dz2 0))
- ((= dz "BL") (setq dz1 0 dz2 1))
- ((= dz "BC") (setq dz1 1 dz2 1))
- ((= dz "BR") (setq dz1 2 dz2 1))
- ((= dz "ML") (setq dz1 0 dz2 2))
- ((= dz "MC") (setq dz1 1 dz2 2))
- ((= dz "MR") (setq dz1 2 dz2 2))
- ((= dz "TL") (setq dz1 0 dz2 3))
- ((= dz "TC") (setq dz1 1 dz2 3))
- ((= dz "TR") (setq dz1 2 dz2 3))
- )
- (entmake
- (list
- '(0 . "TEXT")
- (cons 8 tc);图层
- (cons 10 pt);插入点,必须先预设该值,否则无法运行
- (cons 1 ss);内容
- (cons 40 hh);字高
- (cons 50 rr)
- (cons 41 0.7);字宽
- (cons 72 dz1)
- (cons 73 dz2)
- (cons 11 pt);对齐点
- )
- )
- )
|