Michaels 发表于 2022-7-6 08:44:47

如何检查点是否在

你好
 
如何检查坐标点是否是点列表中的成员?
(setq pts '((27.3814 14.1609 0.0) (24.6235 10.9329 0.0) (19.8956 13.6626 0.0) (17.6971 9.85463 0.0)))

(setq pt '(27.3814 14.1609 0.0))
(member pt pts)

 
提前感谢

LISP2LEARN 发表于 2022-7-6 08:58:51

(defun C:test (/ pts pt)

(setq pts '((27.3814 14.1609 0.0) (24.6235 10.9329 0.0) (19.8956 13.6626 0.0) (17.6971 9.85463 0.0)))
(setq pt '(27.3814 14.1609 0.0))
(if (member pt pts)
(princ "\n Point list found")
(princ "\n Point list not found")
)
(princ)
)

Michaels 发表于 2022-7-6 09:04:54

非常感谢你。
 
我的尝试和你的一样,我真的很奇怪为什么一开始它对我不起作用!!!
 
干杯

David Bethel 发表于 2022-7-6 09:14:25

注意包含real的列表中的(成员)调用。没有模糊因子,因此数字必须精确匹配。这在很大程度上取决于这些数字是如何获得的-大卫

alanjt 发表于 2022-7-6 09:20:00

说得好,大卫。我想你可以自己滚。。。
 
(defun _member (item lst)
(if (car lst)
   (if (equal (car lst) item)
   lst
   (_member item (cdr lst))
   )
)
)

Lee Mac 发表于 2022-7-6 09:23:14

非常优雅的Alan
 
一些变体:
 
(defun _memberwithfuzz ( expr lst fuzz )
   (vl-member-if '(lambda ( x ) (equal x expr fuzz)) lst)
)
(defun _memberwithfuzz ( expr lst fuzz / x )
   (while (and (setq x (car lst)) (not (equal expr x fuzz)))
       (setq lst (cdr lst))
   )
   lst
)
(defun _memberwithfuzz ( expr lst fuzz / foo bar )
   (defun foo ( x ) (equal x expr fuzz))
   (defun bar ( x )
       (if (foo x) (progn (defun foo ( x ) (list x)) (list x)))
   )
   (apply 'append (mapcar 'bar lst))
)

David Bethel 发表于 2022-7-6 09:35:37


;;;SearchAtom List Fuzz
(defun memberfz (s l f / r)
(foreach a l
(and (not r)
       (equal s a f)
       (setq r T)))
r)

 
-大卫

alanjt 发表于 2022-7-6 09:38:47

谢谢,你也是。
 
 
 
具有可定义模糊因子的轻微mod。。。
 
(defun _memberFuzz (item lst fuzz)
(if (car lst)
   (if (equal (car lst) item fuzz)
   lst
   (_member item (cdr lst) fuzz)
   )
)
)

Michaels 发表于 2022-7-6 09:49:33

谢谢大家,
 
我有很多东西要读。
 
非常感谢。
页: [1]
查看完整版本: 如何检查点是否在