乐筑天下

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

[编程交流] 值相同但不相同?

[复制链接]

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 09:44:05 | 显示全部楼层 |阅读模式
好的,我发现了一些最奇怪的错误。
 
背景:
 
我试图找出两个矩形是否相交,如果它们在超过一个给定点上相交(即角点仅接触),它将把它添加到矩形相交列表中。
 
  1.         (if (and(and (<= (min ax1 ax2) bx1) (>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by1) (>= (max ay1 ay2) by1)))(setq int 1))
  2.        (if (and(and (<= (min ax1 ax2) bx1) (>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by2) (>= (max ay1 ay2) by2)))(setq int 1))
  3.        (if (and(and (<= (min ax1 ax2) bx2) (>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by1) (>= (max ay1 ay2) by1)))(setq int 1))
  4.        (if (and(and (<= (min ax1 ax2) bx2) (>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by2) (>= (max ay1 ay2) by2)))(setq int 1))

是的,我知道我应该使用cond,但cond不允许我需要超过1张支票。
 
好的,现在是设置和错误。
 
设置:
  1. (setq acomp (nth 12 wlist))
  2.    (setq aname (nth 0 acomp))
  3.    (setq ax1 (nth 1 acomp))
  4.    (setq ay1 (nth 2 acomp))
  5.    (setq ax2 (nth 3 acomp))
  6.    (setq ay2 (nth 4 acomp))
  7.    (setq adir (nth 7 acomp))
  8. (setq bcomp (nth 9 wlist))
  9.      (setq bname (nth 0 bcomp))
  10.      (setq bx1 (nth 1 bcomp))
  11.      (setq by1 (nth 2 bcomp))
  12.      (setq bx2 (nth 3 bcomp))
  13.      (setq by2 (nth 4 bcomp))
  14.      (setq bdir (nth 7 bcomp))
  15. ("P3" 202.0 175.0 226.0 178.0 202.0 176.5 "X")
  16. "P3"
  17. 202.0
  18. 175.0
  19. 226.0
  20. 178.0
  21. "X"
  22. ("W10" 198.0 142.0 202.0 254.0 200.0 142.0 "Y")
  23. "W10"
  24. 198.0
  25. 142.0
  26. 202.0
  27. 254.0
  28. "Y"
错误:
  1. _$ ax1
  2. 202.0
  3. _$ ax2
  4. 226.0
  5. _$ bx2
  6. 202.0
  7. _$ (min ax1 ax2)
  8. 202.0
  9. _$ (<= (min ax1 ax2) bx2)
  10. nil

 
您最好的选择可能是在计算中引入“模糊”因子,您可以使用“相等”函数来实现。
 
如果您希望清理代码,请尝试包装所有(和…)函数转换为单个(和…)函数或(或…)。这样,每个人都将被评估,而不需要有一堆if。这是一个很好的提示;如果你有很多非常相似的if,考虑把它们变成某种循环;你也许可以节省一些空间并将其清理干净。
 
希望这有帮助,至少有一点!
回复

使用道具 举报

20

主题

344

帖子

325

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
100
发表于 2022-7-6 10:04:00 | 显示全部楼层
方程得出:
  1. Command: (= pi 3.1415926535897932)
  2. T
  3. Command: (= pi 3.1415926535897933)
  4. T

但这再次带来了错误的矩形相交。
谢谢你教我一个新命令。
 
有没有办法把四舍五入到最接近的1/64英寸或1/32英寸。这将通过将交点转换为预期值来停止假矩形交点。
 
此外,为了清晰起见,这里有一些修订的代码。更好地理解我在做什么。
 
  1. _$ (Equal (min ax1 ax2) bx2 0.00000001)
  2. T
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 10:14:41 | 显示全部楼层
Ok全部固定
 
谢谢你的帮助。
 
圆形函数:
  1.     (setq int 0)
  2.     (if
  3.       (and
  4.           (and (<= (min ax1 ax2) bx1)
  5.                (>= (max ax1 ax2) bx1)
  6.           );;point 1's x is between or on Rectangle
  7.           (and (<= (min ay1 ay2) by1)
  8.                (>= (max ay1 ay2) by1)
  9.           );;point 1's y is between or on Rectangle
  10.        );;point 1 is between or on Rectangle
  11.      (setq int (+ int 1));; Rectangles intersect add to intesections
  12.      );;end if
  13.     (if
  14.       (and
  15.           (and (<= (min ax1 ax2) bx1)
  16.                (>= (max ax1 ax2) bx1)
  17.            );;point 2's x is between or on Rectangle
  18.           (and (<= (min ay1 ay2) by2)
  19.                (>= (max ay1 ay2) by2)
  20.           );;point 2's y is between or on Rectangle
  21.       );;point 2 is in or on Rectangle
  22.       (setq int (+ int 1));; Rectangles intersect add to intesections
  23.       );;end if
  24.     (if
  25.       (and
  26.           (and (<= (min ax1 ax2) bx2)
  27.                (>= (max ax1 ax2) bx2)
  28.            );;point 3's x is between or on Rectangle
  29.           (and (< (min ay1 ay2) by1)
  30.               (> (max ay1 ay2) by1)
  31.           );;point 3's y is between or on Rectangle
  32.         );;point 3 is in or on Rectangle
  33.       (setq int (+ int 1));; Rectangles intersect add to intesections
  34.       );;end if
  35.     (if
  36.       (and
  37.           (and (<= (min ax1 ax2) bx2)
  38.                (>= (max ax1 ax2) bx2)
  39.           );;point 4's x is between or on Rectangle
  40.           (and (<= (min ay1 ay2) by2)
  41.                (>= (max ay1 ay2) by2)
  42.           );;point 4's y is between or on Rectangle
  43.        );;point 4 is in or on Rectangle
  44.       (setq int (+ int 1));; Rectangles intersect add to intesections
  45.       );;end if

 
矩形检查:
  1. (defun round (number xth / ro x y out)
  2.    (if (> xth 0)
  3.      (progn
  4. (setq ro (rem number 1))
  5. (setq x (- number ro))
  6. (if (>= (rem (* (expt 10 xth) ro) 1) 0.5) (setq add 1) (setq add 0))
  7. (setq y (/(- (* (expt 10 xth) ro) (- (rem (* (expt 10 xth) ro) 1) add)) (expt 10 xth)))
  8. (setq out (+ x y))
  9. )
  10.      )
  11.    (if (= xth 0)
  12.      (progn
  13. (setq ro (rem number 1))
  14. (setq out (- number ro))
  15. )
  16.      )
  17.    (if (< xth 0)
  18.      (progn
  19. (setq xth (* xth -1))
  20. (setq ro (rem (/ number (expt 10 xth)) 1))
  21. (setq out (* (- (/ number (expt 10 xth)) ro)(expt 10 xth)))
  22. )
  23.      )
  24.    out
  25.    )

 
 
输入:
  1.     (setq int 0)
  2.     (if(and(and(<= (min ax1 ax2) bx1)(>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by1)(>= (max ay1 ay2) by1)))(setq int (+ int 1)))
  3.     (if(and(and(<= (min ax1 ax2) bx1)(>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by2)(>= (max ay1 ay2) by2)))(setq int (+ int 1)))
  4.     (if(and(and(<= (min ax1 ax2) bx2)(>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by1)(>= (max ay1 ay2) by1)))(setq int (+ int 1)))
  5.     (if(and(and(<= (min ax1 ax2) bx2)(>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by2)(>= (max ay1 ay2) by2)))(setq int (+ int 1)))
  6.     (if (> int 1) (progn))

 
输出:
  1. _$ (setq acomp (nth 1 wlist))
  2.    (setq aname (nth 0 acomp))
  3.    (setq ax1 (round (nth 1 acomp) 4))
  4.    (setq ay1 (round (nth 2 acomp) 4))
  5.    (setq ax2 (round (nth 3 acomp) 4))
  6.    (setq ay2 (round (nth 4 acomp) 4))
  7.    (setq adir (nth 7 acomp))
  8. (setq bcomp (nth 0 wlist))
  9.      (setq bname (nth 0 bcomp))
  10.      (setq bx1 (round (nth 1 bcomp) 4))
  11.      (setq by1 (round (nth 2 bcomp) 4))
  12.      (setq bx2 (round (nth 3 bcomp) 4))
  13.      (setq by2 (round (nth 4 bcomp) 4))
  14.      (setq bdir (nth 7 bcomp))
  15. ("W2" 326.0 6.0 330.0 138.0 328.0 6.0 "Y")
  16. "W2"
  17. 326.0
  18. 6.0
  19. 330.0
  20. 138.0
  21. "Y"
  22. ("W1" 22.0 6.0 326.0 10.0 22.0 8.0 "X")
  23. "W1"
  24. 22.0
  25. 6.0
  26. 326.0
  27. 10.0
  28. "X"
回复

使用道具 举报

13

主题

48

帖子

35

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 10:20:58 | 显示全部楼层
is\u point\u in\u box测试可以压缩很多
 
 
  1. 0
  2. nil
  3. nil
  4. 1
  5. 2

 
 
-大卫
回复

使用道具 举报

26

主题

1495

帖子

20

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 10:35:10 | 显示全部楼层
“圆形”函数也可以极大地压缩:
 
  1. [color=#8b4513];;;ARG -> Test_pt Corner_Pt1 Corner_Pt2[/color]
  2. [color=#8b4513];;;RET -> T nil[/color]
  3. [b][color=BLACK]([/color][/b]defun is_pt_in_box [b][color=FUCHSIA]([/color][/b]tp p1 p2 / x1 x2 y1 y2[b][color=FUCHSIA])[/color][/b]
  4.   [b][color=FUCHSIA]([/color][/b]setq x1 [b][color=NAVY]([/color][/b]car p1[b][color=NAVY])[/color][/b]  x2 [b][color=NAVY]([/color][/b]car p2[b][color=NAVY])[/color][/b]
  5.         y1 [b][color=NAVY]([/color][/b]cadr p1[b][color=NAVY])[/color][/b] y2 [b][color=NAVY]([/color][/b]cadr p2[b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b]
  6.   [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]>= [b][color=MAROON]([/color][/b]max x1 x2[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]car tp[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]min x1 x2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b]
  7.        [b][color=NAVY]([/color][/b]>= [b][color=MAROON]([/color][/b]max y1 y2[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]cadr tp[b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]min y1 y2[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b]
回复

使用道具 举报

114

主题

1万

帖子

1万

银币

中流砥柱

Rank: 25

铜币
543
发表于 2022-7-6 10:49:48 | 显示全部楼层
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-6 23:35 , Processed in 0.411736 second(s), 75 queries .

© 2020-2025 乐筑天下

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