ynhh 发表于 2019-10-3 22:28:55

求点集表中到指定图元最近的点

请教各位大师
已知点集表和一个曲线类图元
求点集表中到指定图元最近的点
谢谢

caoyin 发表于 2019-10-4 09:23:26

本帖最后由 caoyin 于 2019-10-4 09:27 编辑

(defun getClosestPoint (CRV PLST / DST PNT)
(foreach P PLST
    (setq D (distance (vlax-curve-getClosestPointTo CRV P) P))
    (if (or (not DST) (< D DST))
      (setq DST D
            PNT P
      )
    )
)
PNT
);;测试
(getClosestPoint (car(entsel "\n选择曲线"))
               (while (setq p (getpoint "\n拾取点"))
                   (setq PTS (cons P PTS))
               )
)

ynhh 发表于 2019-10-4 15:13:10

caoyin 发表于 2019-10-4 09:23
(defun getClosestPoint (CRV PLST / DST PNT)
(foreach P PLST
    (setq D (distance (vlax-curve-ge ...

谢谢您的热心指导
我再好好学习一下
衷心感谢您

llsheng_73 发表于 2019-10-11 15:33:03

(defun getclosetpoint(crv pt)
(nth(car(vl-sort-i(mapcar'(lambda(x)(distance(vlax-curve-getClosestPointTo crv x)x))pt)'<))pt)
)

ynhh 发表于 2019-10-14 16:21:19

llsheng_73 发表于 2019-10-11 15:33


谢谢您的指导
您的写法经典简洁
谢谢您

caoyin 发表于 2019-10-14 17:57:44

4楼的代码,vl-sort-i    mapcar是两次遍历点集。

happy336 发表于 2019-10-14 19:56:02

顶一下,嘿嘿
页: [1]
查看完整版本: 求点集表中到指定图元最近的点