时见申 发表于 2018-8-31 11:32:56

判断点在线上

(defun donpl( pt plname / vlist p1 p2 x1 x2 y1 y2 a b xt yt ax n)
(setq vlist (vl-remove-if'not(mapcar'(lambda(x) (if (= (car x) 10) (cdr x))) (entget plname))))
        (setq n 0)
        (while (and p2 (not jg))
                (setq p1 (nth n vlist)
                        p2 (nth (+ n 1) vlist)
                        x1 (car p1)
                        y1 (cadr p1)
                        x2 (car p2)
                        y2 (cadr p2)
                        a (/ (- y1 y2) (- x1 x2))
                        b (- y1 (/ (* x1 (- y1 y2)) (- x1 x2)))
                        xt (car pt)
                        yt (cadr pt)
                        ax (+ (* xt a) b)
                )
               
                (setq jg (equal ax yt 0.001))
                (setq n (1+ n))
        )
        jg
)

lijiao 发表于 2022-2-17 11:33:22

cghdy 发表于 2022-2-16 16:30
能否区分在线上和在延长线上

(setq on1 (equal pt (vlax-curve-getClosestPointTo plname pt) 0.000001))
(setq on2 (equal pt (vlax-curve-getClosestPointTo plname pt t) 0.000001))
(cond
((and on1 on2) (princ "在线上"))
((and (not on1) on2) (princ "在延长线上"))
(t (princ "在线外"))
)

lijiao 发表于 2018-8-31 14:19:22

(equal pt (vlax-curve-getClosestPointTo plname pt) 0.000001)

yanshengjiang 发表于 2024-12-23 20:42:47

lijiao 发表于 2022-2-17 11:33


应该没这么简单吧   我在别人那儿捡了一段代码:

;;164.47.3 [功能] pt到曲线的垂点不在延长线上,返回T
;;(HH:perPtIn (getpoint) (car(entsel)))
(defun HH:perPtIn (p curve / P1 P2 PA)
(setq p1 (vlax-curve-getClosestPointTo curve p))
(setq pa (vlax-curve-getParamAtPoint curve P1))          ;参数
(setq p2 (mapcar '+ (vlax-curve-getFirstDeriv curve pa) p1)) ;切线上一点
(equal (caddr (trans (mapcar '- p p1) 0 (mapcar '- p2 p1))) 0 1e-5)
)

时见申 发表于 2018-8-31 15:29:49

lijiao 发表于 2018-8-31 14:19


新手函数太少,谢谢大神指点,万分感谢

taoyi0727 发表于 2018-9-1 09:13:50

lijiao 发表于 2018-8-31 14:19


这个写好可惜我不会VL

疯球 发表于 2018-9-1 14:46:13

谢谢楼主分享!!!!!!

cghdy 发表于 2022-2-16 16:30:26

lijiao 发表于 2018-8-31 14:19


能否区分在线上和在延长线上

自贡黄明儒 发表于 2022-2-17 08:34:05

cghdy 发表于 2022-2-16 16:30
能否区分在线上和在延长线上

要判断是否在延长线上,最简单的办法是在P点产生一根直线,用vla-IntersectWith来判断。

cghdy 发表于 2022-2-18 13:39:27

lijiao 发表于 2022-2-17 11:33


好办法:handshake

cghdy 发表于 2022-2-18 13:40:29

自贡黄明儒 发表于 2022-2-17 08:34
要判断是否在延长线上,最简单的办法是在P点产生一根直线,用vla-IntersectWith来判断。

lijiao回复的vlax-curve-getClosestPointTo是带了这个功能的
页: [1] 2
查看完整版本: 判断点在线上