明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 501|回复: 7

[提问] 坐标列表到列表外一点的最近点

[复制链接]
发表于 2023-8-17 08:20 | 显示全部楼层 |阅读模式
(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最近的一点,上面的写法在特定条件下是正确的,但大部分情况不对,请教一下正确的写法

"觉得好,就打赏"
还没有人打赏,支持一下
发表于 2023-8-17 08:45 | 显示全部楼层

(SETQ PT (nth 0 ns))
(FOREACH X (CDR NS)
  (SETQ        IS1 (distance PT3 PT)
        IS2 (distance PT3 X)
  )
  (IF (>= is1 is2)
    (SETQ PT X)
  )
)
发表于 2023-8-17 09:06 | 显示全部楼层
  1. (setq ns1 (mapcar '(lambda(x)
  2.                      (cons (distance x pt3) x))
  3.                   ns)
  4.       dismin (apply 'min (mapcar 'car ns1))
  5.       pt (cdr (assoc dismin ns1)))

点评

也是这个思路  发表于 2023-8-17 11:15
 楼主| 发表于 2023-8-18 08:51 | 显示全部楼层
谢谢上面两位朋友的热心指导
发表于 2023-8-18 12:15 | 显示全部楼层
本帖最后由 花开富贵 于 2023-8-18 12:17 编辑

[size=12.6825pt]
  • ;;说明:计算列表中到指定点的最短距离以及此点坐标
  • ;;参数: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[size=12.6825pt](x)
  •        (setq discur(distance x ptSpeci))
  •        (if(or(null dis0818)(< discur dis0818))  (setq[size=12.6825pt] dis0818 discur ret (cons[size=12.6825pt] x discur))       )
  •      )
  •     ptLst)
  •   ret
  • )

发表于 2023-8-18 12:19 | 显示全部楼层
花开富贵 发表于 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
    )
    发表于 2024-2-17 10:00 | 显示全部楼层
    楼上,我刚刷到,能举个实例么?
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
    ©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

    GMT+8, 2024-5-3 07:14 , Processed in 0.415828 second(s), 29 queries , Gzip On.

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表