CADWarrior 发表于 2022-7-6 09:44:05

值相同但不相同?

好的,我发现了一些最奇怪的错误。
 
背景:
 
我试图找出两个矩形是否相交,如果它们在超过一个给定点上相交(即角点仅接触),它将把它添加到矩形相交列表中。
 
      (if (and(and (<= (min ax1 ax2) bx1) (>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by1) (>= (max ay1 ay2) by1)))(setq int 1))
       (if (and(and (<= (min ax1 ax2) bx1) (>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by2) (>= (max ay1 ay2) by2)))(setq int 1))
       (if (and(and (<= (min ax1 ax2) bx2) (>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by1) (>= (max ay1 ay2) by1)))(setq int 1))
       (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张支票。
 
好的,现在是设置和错误。
 
设置:
(setq acomp (nth 12 wlist))
   (setq aname (nth 0 acomp))
   (setq ax1 (nth 1 acomp))
   (setq ay1 (nth 2 acomp))
   (setq ax2 (nth 3 acomp))
   (setq ay2 (nth 4 acomp))
   (setq adir (nth 7 acomp))


(setq bcomp (nth 9 wlist))
   (setq bname (nth 0 bcomp))
   (setq bx1 (nth 1 bcomp))
   (setq by1 (nth 2 bcomp))
   (setq bx2 (nth 3 bcomp))
   (setq by2 (nth 4 bcomp))
   (setq bdir (nth 7 bcomp))
("P3" 202.0 175.0 226.0 178.0 202.0 176.5 "X")
"P3"
202.0
175.0
226.0
178.0
"X"
("W10" 198.0 142.0 202.0 254.0 200.0 142.0 "Y")
"W10"
198.0
142.0
202.0
254.0
"Y"错误:
_$ ax1
202.0
_$ ax2
226.0
_$ bx2
202.0
_$ (min ax1 ax2)
202.0
_$ (<= (min ax1 ax2) bx2)
nil
 
您最好的选择可能是在计算中引入“模糊”因子,您可以使用“相等”函数来实现。
 
如果您希望清理代码,请尝试包装所有(和…)函数转换为单个(和…)函数或(或…)。这样,每个人都将被评估,而不需要有一堆if。这是一个很好的提示;如果你有很多非常相似的if,考虑把它们变成某种循环;你也许可以节省一些空间并将其清理干净。
 
希望这有帮助,至少有一点!

Freerefill 发表于 2022-7-6 10:04:00

方程得出:

Command: (= pi 3.1415926535897932)
T
Command: (= pi 3.1415926535897933)
T

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

_$ (Equal (min ax1 ax2) bx2 0.00000001)
T

CADWarrior 发表于 2022-7-6 10:14:41

Ok全部固定
 
谢谢你的帮助。
 
圆形函数:

    (setq int 0)

    (if
      (and
          (and (<= (min ax1 ax2) bx1)
               (>= (max ax1 ax2) bx1)
          );;point 1's x is between or on Rectangle
          (and (<= (min ay1 ay2) by1)
               (>= (max ay1 ay2) by1)
          );;point 1's y is between or on Rectangle
       );;point 1 is between or on Rectangle
   (setq int (+ int 1));; Rectangles intersect add to intesections
   );;end if

    (if
      (and
          (and (<= (min ax1 ax2) bx1)
               (>= (max ax1 ax2) bx1)
         );;point 2's x is between or on Rectangle
          (and (<= (min ay1 ay2) by2)
               (>= (max ay1 ay2) by2)
          );;point 2's y is between or on Rectangle
      );;point 2 is in or on Rectangle
      (setq int (+ int 1));; Rectangles intersect add to intesections
      );;end if

    (if
      (and
          (and (<= (min ax1 ax2) bx2)
               (>= (max ax1 ax2) bx2)
         );;point 3's x is between or on Rectangle
          (and (< (min ay1 ay2) by1)
            (> (max ay1 ay2) by1)
          );;point 3's y is between or on Rectangle
      );;point 3 is in or on Rectangle
      (setq int (+ int 1));; Rectangles intersect add to intesections
      );;end if

    (if
      (and
          (and (<= (min ax1 ax2) bx2)
               (>= (max ax1 ax2) bx2)
          );;point 4's x is between or on Rectangle
          (and (<= (min ay1 ay2) by2)
               (>= (max ay1 ay2) by2)
          );;point 4's y is between or on Rectangle
       );;point 4 is in or on Rectangle
      (setq int (+ int 1));; Rectangles intersect add to intesections
      );;end if

 
矩形检查:

(defun round (number xth / ro x y out)
   (if (> xth 0)
   (progn
(setq ro (rem number 1))
(setq x (- number ro))
(if (>= (rem (* (expt 10 xth) ro) 1) 0.5) (setq add 1) (setq add 0))
(setq y (/(- (* (expt 10 xth) ro) (- (rem (* (expt 10 xth) ro) 1) add)) (expt 10 xth)))
(setq out (+ x y))
)
   )
   (if (= xth 0)
   (progn
(setq ro (rem number 1))
(setq out (- number ro))
)
   )
   (if (< xth 0)
   (progn
(setq xth (* xth -1))
(setq ro (rem (/ number (expt 10 xth)) 1))
(setq out (* (- (/ number (expt 10 xth)) ro)(expt 10 xth)))
)
   )
   out
   )
 
 
输入:


    (setq int 0)
    (if(and(and(<= (min ax1 ax2) bx1)(>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by1)(>= (max ay1 ay2) by1)))(setq int (+ int 1)))
    (if(and(and(<= (min ax1 ax2) bx1)(>= (max ax1 ax2) bx1))(and (<= (min ay1 ay2) by2)(>= (max ay1 ay2) by2)))(setq int (+ int 1)))
    (if(and(and(<= (min ax1 ax2) bx2)(>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by1)(>= (max ay1 ay2) by1)))(setq int (+ int 1)))
    (if(and(and(<= (min ax1 ax2) bx2)(>= (max ax1 ax2) bx2))(and (<= (min ay1 ay2) by2)(>= (max ay1 ay2) by2)))(setq int (+ int 1)))
    (if (> int 1) (progn))

 
输出:

_$ (setq acomp (nth 1 wlist))
   (setq aname (nth 0 acomp))
   (setq ax1 (round (nth 1 acomp) 4))
   (setq ay1 (round (nth 2 acomp) 4))
   (setq ax2 (round (nth 3 acomp) 4))
   (setq ay2 (round (nth 4 acomp) 4))
   (setq adir (nth 7 acomp))

(setq bcomp (nth 0 wlist))
   (setq bname (nth 0 bcomp))
   (setq bx1 (round (nth 1 bcomp) 4))
   (setq by1 (round (nth 2 bcomp) 4))
   (setq bx2 (round (nth 3 bcomp) 4))
   (setq by2 (round (nth 4 bcomp) 4))
   (setq bdir (nth 7 bcomp))
("W2" 326.0 6.0 330.0 138.0 328.0 6.0 "Y")
"W2"
326.0
6.0
330.0
138.0
"Y"
("W1" 22.0 6.0 326.0 10.0 22.0 8.0 "X")
"W1"
22.0
6.0
326.0
10.0
"X"

CADWarrior 发表于 2022-7-6 10:20:58

is\u point\u in\u box测试可以压缩很多
 
 

0
nil
nil
1
2
 
 
-大卫

David Bethel 发表于 2022-7-6 10:35:10

“圆形”函数也可以极大地压缩:
 

;;;ARG -> Test_pt Corner_Pt1 Corner_Pt2
;;;RET -> T nil
(defun is_pt_in_box (tp p1 p2 / x1 x2 y1 y2)
(setq x1 (car p1)x2 (car p2)
      y1 (cadr p1) y2 (cadr p2))
(and (>= (max x1 x2) (car tp) (min x1 x2))
       (>= (max y1 y2) (cadr tp) (min y1 y2))))

Lee Mac 发表于 2022-7-6 10:49:48

页: [1]
查看完整版本: 值相同但不相同?