判断点在线上
(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
)
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 "在线外"))
) (equal pt (vlax-curve-getClosestPointTo plname pt) 0.000001) 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)
) lijiao 发表于 2018-8-31 14:19
新手函数太少,谢谢大神指点,万分感谢 lijiao 发表于 2018-8-31 14:19
这个写好可惜我不会VL 谢谢楼主分享!!!!!! lijiao 发表于 2018-8-31 14:19
能否区分在线上和在延长线上 cghdy 发表于 2022-2-16 16:30
能否区分在线上和在延长线上
要判断是否在延长线上,最简单的办法是在P点产生一根直线,用vla-IntersectWith来判断。 lijiao 发表于 2022-2-17 11:33
好办法:handshake 自贡黄明儒 发表于 2022-2-17 08:34
要判断是否在延长线上,最简单的办法是在P点产生一根直线,用vla-IntersectWith来判断。
lijiao回复的vlax-curve-getClosestPointTo是带了这个功能的
页:
[1]
2