坐标列表到列表外一点的最近点
(setq n 0)(while (and (setq ss1 (nth n ns)) ;取得第n点的坐标
(setq ww1 (vl-position ss1 ns)) ;取得第n点坐标在交点坐标列表中的位置
(setq ss2 (nth (1+ ww1) ns)) ;取得第n点下一个点的坐标
(setq is1 (distance ss1 pt3))
(setq is2 (distance ss2 pt3)) ;取得两个坐标点的距离
)
(if(<= is1 is2 )
(setq pt ss1)
(setq pt ss2)
)
(setq n (1+ n))
)
NS是坐标列表 PT3是列表外一点,要找出NS中距PT3最近的一点,上面的写法在特定条件下是正确的,但大部分情况不对,请教一下正确的写法
(SETQ PT (nth 0 ns))
(FOREACH X (CDR NS)
(SETQ IS1 (distance PT3 PT)
IS2 (distance PT3 X)
)
(IF (>= is1 is2)
(SETQ PT X)
)
)
(setq ns1 (mapcar '(lambda(x)
(cons (distance x pt3) x))
ns)
dismin (apply 'min (mapcar 'car ns1))
pt (cdr (assoc dismin ns1))) 谢谢上面两位朋友的热心指导 本帖最后由 花开富贵 于 2023-8-18 12:17 编辑
[*];;说明:计算列表中到指定点的最短距离以及此点坐标
[*];;参数:ptSpeci:指定点坐标
[*];;参数:ptLst:列表,成员为点坐标
[*];;返回:列表
[*](defun Point::Near(ptSpeci ptLst / discur ret dis0818)
[*];;(car (Point::Near '(1 1) '((0 0) (10 0) (10 10))))-->(0 0)
[*](mapcar'(lambda(x)
[*] (setq discur(distance x ptSpeci))
[*] (if(or(null dis0818)(< discur dis0818))(setq dis0818 discur ret (cons x discur)) )
[*] )
[*] ptLst)
[*]ret
[*])
花开富贵 发表于 2023-8-18 12:15
[*];;说明:计算列表中到指定点的最短距离以及此点坐标
[*];;参数:ptSpeci:指定点坐标
[*];;参数:ptLst: ...
;;说明:计算列表中到指定点的最短距离以及此点坐标
;;参数:ptSpeci:指定点坐标
;;参数:ptLst:列表,成员为点坐标
;;返回:列表
(defun Point::Near(ptSpeci ptLst / discur ret dis0818)
;;(car (Point::Near '(1 1) '((0 0) (10 0) (10 10))))-->(0 0)
(mapcar '(lambda(x)
(setq discur(distance x ptSpeci))
(if(or(null dis0818)(< discur dis0818)) (setq dis0818 discur ret (cons x discur)) )
)
ptLst)
ret
) 楼上,我刚刷到,能举个实例么?
页:
[1]