文本方向问题
嗨,我已经在这个Lisp程序的工作了几天。起初,我的一位同事要求我用Lisp程序评分,我找到了戈登·斯蒂芬斯的Lisp程序评分。结果表明,他们想要一个带有箭头Lisp程序的百分比坡度和/或带有三角形Lisp程序的倾斜坡度。我设法使倾斜Lisp程序的工作,但一年级一直给我带来麻烦。目前,只要用户选择左边的第一个点和右边的第二个点,我就可以给我右方向的文本。另一个方向要么文字消失,要么文字颠倒,我一直无法找出原因。
我的逻辑或编码哪里出了问题,可以给我一些指导吗?
(defun c:grade (/ pnt1 pnt2 ang1 ang2 tanofang grade1 midpt osmd txt1 hp1 vp1 hp2 vp2 midapt lpt1 lpt2)
; Grade Lisp by Gordon Stephens. Heavily edited to add a dim arrow by Mark Clews with snippets of code from experts like Lee Mac
;; clear most command text from commandline
(setvar "cmdecho" 0)
;; Error coding begins
(defun *error* ( msg )
(if osm (setvar 'osmode osm))
(cond ((not msg))
((member msg '("Function cancelled" "quit / exit abort")))
((princ (strcat "\n*** Error: " msg " ** ")))
)
(princ)
) ;; End of error Coding
;; Set basic variables
(prompt "\npick points for the grade")
(setq pnt1 (getpoint) pnt2 (getpoint pnt1))
;;If statements to determine angle standard between -90° and +90°
(setq osmd (getvar "osmode"))
(setvar "osmode" 0)
(setq ang1 (angle pnt1 pnt2))
(setq tanofang (/ (sin ang1) (cos ang1)))
(if (= tanofang 0) (setq grade1 0.0)
(setq grade1 (/ 1 tanofang))
) ; endif
;;Create the Text
(setq txt1 (strcat (rtos (abs (/ 100 grade1)) 2 1) "%" ))
(setq midpt (list (/ (+ (car pnt1) (car pnt2)) 2) (+ (/ (+ (cadr pnt1) (cadr pnt2)) 2) 5)))
;;Orientation of text If the value of the number from multiplying x and y is positive
(If (> 0 (- (car pnt1) (car pnt2))) ;this is the one going wrong
(setq ang2 (rtd ang1))
;; Add Text
(command "text" "mc" midpt 2.5 ang2 txt1) ; middle centre justified
) ;;End If
;;Orientation of text If the value of the number from multiplying x and y is negative
(If (< 0 (- (car pnt1) (car pnt2)))
(setq ang2 (rtd (- ang1 180)))
;; Add Text
(command "text" "mc" midpt 2.5 ang2 txt1) ; middle centre justified
) ;;End If
;;Create the arrows
;;Set independant origin point
(setq midapt (list (/ (+ (car pnt1) (car pnt2)) 2) (+ (/ (+ (cadr pnt1) (cadr pnt2)) 2) 2.5)))
;;Determine the value of Sin * Cos (negative will be between 90° to 180° or above 270° and down will
;;be to the right. For all other angles, down will be to the left)
(setq sinvscos (* (- (car pnt2) (car pnt1)) (- (cadr pnt2) (cadr pnt1))))
;;If the value of the sin and cos lengths is negative create leader arrow pointing left
(if (< 0 sinvscos)
(progn
;; First set XY values for Points
(setq hp1 (- (car midapt) (abs (* (cos ang1) 5))))
(setq vp1 (- (cadr midapt) (abs (* (sin ang1) 5))))
(setq lpt1 (strcat (rtos hp1) "," (rtos vp1)))
(setq hp2 (+ (car midapt) (abs (* (cos ang1) 5))))
(setq vp2 (+ (cadr midapt) (abs (* (sin ang1) 5))))
(setq lpt2 (strcat (rtos hp2) "," (rtos vp2)))
;;Draw Arrow
(command "leader" lpt1 lpt2 "a" "" "n")
) ;end progn
) ;end if
;;If the value of the sin and cos lengths is positive create leader arrow pointing right
(if (> 0 sinvscos)
(progn
;; First set XY values for Points
(setq hp1 (+ (car midapt) (abs (* (cos ang1) 5))))
(setq vp1 (- (cadr midapt) (abs (* (sin ang1) 5))))
(setq lpt1 (strcat (rtos hp1) "," (rtos vp1)))
(setq hp2 (- (car midapt) (abs (* (cos ang1) 5))))
(setq vp2 (+ (cadr midapt) (abs (* (sin ang1) 5))))
(setq lpt2 (strcat (rtos hp2) "," (rtos vp2)))
;;Draw Arrow
(command "leader" lpt1 lpt2 "a" "" "n")
) ;end progn
) ;end if
(setvar "osmode" osmd)
(princ)
) ; end defun
(defun rtd (a)
(/ (* a 180.0) pi)
) ; end defun
您可以检查文本角度,如果大于一个值,则添加Pi(+Pi ang),这将为您翻转角度。角度以弧度表示,因此360度=2*pi 谢谢Bigal,明天我将在工作中使用弧度仔细研究数学函数。尽管如此,这并不能帮助我理解为什么If逻辑让我失望。当我将第一个If语句更改为使用弧度基时,文本仍然缺失,此外,因为我想保留起作用的x+逻辑文本,我切换了两个If语句集,因此文本在两个参数集中都消失了。很明显,我的If语句实际上并不正确,因为如果第二个语句逻辑正确,那么切换位置不应该影响测试。明天我还将花时间查看“类似”的帖子,因为它们可能会为我提供另一条关于我做错了什么的线索。
谢谢Bigal,我仔细看了一下,决定用一个与弧度完美匹配的“cond”集替换整个文本方向“if”集
如果角度小于90°((
页:
[1]