乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 6|回复: 3

[编程交流] 文本方向问题

[复制链接]

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 14:59:44 | 显示全部楼层 |阅读模式
嗨,我已经在这个Lisp程序的工作了几天。起初,我的一位同事要求我用Lisp程序评分,我找到了戈登·斯蒂芬斯的Lisp程序评分。结果表明,他们想要一个带有箭头Lisp程序的百分比坡度和/或带有三角形Lisp程序的倾斜坡度。我设法使倾斜Lisp程序的工作,但一年级一直给我带来麻烦。
目前,只要用户选择左边的第一个点和右边的第二个点,我就可以给我右方向的文本。另一个方向要么文字消失,要么文字颠倒,我一直无法找出原因。
我的逻辑或编码哪里出了问题,可以给我一些指导吗?
 
  1. (defun c:grade (/ pnt1 pnt2 ang1 ang2 tanofang grade1 midpt osmd txt1 hp1 vp1 hp2 vp2 midapt lpt1 lpt2)
  2. ; Grade Lisp by Gordon Stephens. Heavily edited to add a dim arrow by Mark Clews with snippets of code from experts like Lee Mac
  3. ;; clear most command text from commandline
  4. (setvar "cmdecho" 0)
  5. ;; Error coding begins
  6. (defun *error* ( msg )
  7.        (if osm (setvar 'osmode osm))
  8.        (cond ((not msg))
  9.         ((member msg '("Function cancelled" "quit / exit abort")))
  10.            ((princ (strcat "\n*** Error: " msg " ** ")))
  11.        )
  12.        (princ)
  13.    ) ;; End of error Coding
  14.         ;; Set basic variables
  15.                 (prompt "\npick points for the grade")
  16.                 (setq pnt1 (getpoint) pnt2 (getpoint pnt1))
  17.                         ;;If statements to determine angle standard between -90° and +90°
  18.                                 (setq osmd (getvar "osmode"))
  19.                                 (setvar "osmode" 0)
  20.                                 (setq ang1 (angle pnt1 pnt2))
  21.                                 (setq tanofang (/ (sin ang1) (cos ang1)))
  22.                                 (if (= tanofang 0) (setq grade1 0.0)
  23.                                         (setq grade1 (/ 1 tanofang))
  24.                                 ) ; endif
  25.                         ;;Create the Text
  26.                                 (setq txt1 (strcat (rtos (abs (/ 100 grade1)) 2 1) "%" ))
  27.                                 (setq midpt (list (/ (+ (car pnt1) (car pnt2)) 2) (+ (/ (+ (cadr pnt1) (cadr pnt2)) 2) 5)))
  28.                                         ;;Orientation of text If the value of the number from multiplying x and y is positive
  29.                                                 (If (> 0 (- (car pnt1) (car pnt2))) ;this is the one going wrong
  30.                                                 (setq ang2 (rtd ang1))
  31.                                                 ;; Add Text
  32.                                                         (command "text" "mc" midpt 2.5 ang2 txt1) ; middle centre justified
  33.                                                 ) ;;End If
  34.                                         ;;Orientation of text If the value of the number from multiplying x and y is negative
  35.                                                 (If (< 0 (- (car pnt1) (car pnt2)))
  36.                                                 (setq ang2 (rtd (- ang1 180)))
  37.                                                 ;; Add Text
  38.                                                         (command "text" "mc" midpt 2.5 ang2 txt1) ; middle centre justified
  39.                                                 ) ;;End If
  40.                         ;;Create the arrows
  41.                                 ;;Set independant origin point
  42.                                         (setq midapt (list (/ (+ (car pnt1) (car pnt2)) 2) (+ (/ (+ (cadr pnt1) (cadr pnt2)) 2) 2.5)))
  43.                                 ;;Determine the value of Sin * Cos (negative will be between 90° to 180° or above 270° and down will
  44.                                 ;;be to the right. For all other angles, down will be to the left)
  45.                                         (setq sinvscos (* (- (car pnt2) (car pnt1)) (- (cadr pnt2) (cadr pnt1))))
  46.                                         ;;If the value of the sin and cos lengths is negative create leader arrow pointing left
  47.                                                 (if (< 0 sinvscos)
  48.                                                         (progn
  49.                                                         ;; First set XY values for Points
  50.                                                                 (setq hp1 (- (car midapt) (abs (* (cos ang1) 5))))
  51.                                                                 (setq vp1 (- (cadr midapt) (abs (* (sin ang1) 5))))
  52.                                                                         (setq lpt1 (strcat (rtos hp1) "," (rtos vp1)))
  53.                                                                 (setq hp2 (+ (car midapt) (abs (* (cos ang1) 5))))
  54.                                                                 (setq vp2 (+ (cadr midapt) (abs (* (sin ang1) 5))))
  55.                                                                         (setq lpt2 (strcat (rtos hp2) "," (rtos vp2)))
  56.                                                         ;;Draw Arrow
  57.                                                                 (command "leader" lpt1 lpt2 "a" "" "n")
  58.                                                         ) ;end progn
  59.                                                 ) ;end if
  60.                                         ;;If the value of the sin and cos lengths is positive create leader arrow pointing right
  61.                                                 (if (> 0 sinvscos)
  62.                                                         (progn
  63.                                                         ;; First set XY values for Points
  64.                                                                 (setq hp1 (+ (car midapt) (abs (* (cos ang1) 5))))
  65.                                                                 (setq vp1 (- (cadr midapt) (abs (* (sin ang1) 5))))
  66.                                                                         (setq lpt1 (strcat (rtos hp1) "," (rtos vp1)))
  67.                                                                 (setq hp2 (- (car midapt) (abs (* (cos ang1) 5))))
  68.                                                                 (setq vp2 (+ (cadr midapt) (abs (* (sin ang1) 5))))
  69.                                                                         (setq lpt2 (strcat (rtos hp2) "," (rtos vp2)))
  70.                                                         ;;Draw Arrow
  71.                                                                         (command "leader" lpt1 lpt2 "a" "" "n")
  72.                                                         ) ;end progn
  73.                                                 ) ;end if
  74.                         (setvar "osmode" osmd)
  75. (princ)
  76. ) ; end defun
  77. (defun rtd (a)
  78. (/ (* a 180.0) pi)
  79. ) ; end defun
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 15:20:18 | 显示全部楼层
您可以检查文本角度,如果大于一个值,则添加Pi(+Pi ang),这将为您翻转角度。角度以弧度表示,因此360度=2*pi
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 15:47:22 | 显示全部楼层
谢谢Bigal,明天我将在工作中使用弧度仔细研究数学函数。尽管如此,这并不能帮助我理解为什么If逻辑让我失望。当我将第一个If语句更改为使用弧度基时,文本仍然缺失,此外,因为我想保留起作用的x+逻辑文本,我切换了两个If语句集,因此文本在两个参数集中都消失了。很明显,我的If语句实际上并不正确,因为如果第二个语句逻辑正确,那么切换位置不应该影响测试。明天我还将花时间查看“类似”的帖子,因为它们可能会为我提供另一条关于我做错了什么的线索。
回复

使用道具 举报

1

主题

5

帖子

4

银币

初来乍到

Rank: 1

铜币
5
发表于 2022-7-5 16:07:31 | 显示全部楼层
 
谢谢Bigal,我仔细看了一下,决定用一个与弧度完美匹配的“cond”集替换整个文本方向“if”集
 
如果角度小于90°((
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 00:49 , Processed in 2.301523 second(s), 60 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表