两对象间距离最小改善
图一
图二
(defun c:dp(/ CURVE1 CURVE2 D L1 L2 OBJ1 OBJ2 DATA P L P1 P2)
(setq
curve1 (car (entsel "\n选取对象一:"))
curve2 (car (entsel "\n选取对象二:"))
)
(if (vlax-invoke
(vlax-ename->vla-object curve1)
'IntersectWith
(vlax-ename->vla-object curve2)
acExtendNone)
(princ "\n曲线相交")
(progn
(setq d 0.01)
(setq l1 (vlax-curve-getDistAtParam curve1 (vlax-curve-getEndParam curve1))
l2 (vlax-curve-getDistAtParam curve2 (vlax-curve-getEndParam curve2))
)
(if (< l1 l2) (setq obj1 curve1 obj2 curve2)
(setq obj1 curve2 obj2 curve1))
(setq data (list (setq p (vlax-curve-getStartPoint obj1))
(vlax-curve-getClosestPointTo obj2 p)))
(setq l d)
(while (< l (min l1 l2))
(setq p1 (vlax-curve-getpointatdist obj1 l)
p2 (vlax-curve-getClosestPointTo obj2 p1)
)
(if (< (distance p1 p2) (apply 'distance data))
(setq data (list p1 p2))
)
(setq l (+ l d))
)
(setq p1 (vlax-curve-getEndPoint obj1)
p2 (vlax-curve-getClosestPointTo obj2 p1)
)
(if (< (distance p1 p2) (apply 'distance data))
(setq data (list p1 p2))
)
(entmake (list '(0 . "line")
'(100 . "AcDbEntity")
'(62 . 3)
(cons 10 (car data))
(cons 11 (cadr data))
)
)
)
)
(alert(strcat "\n两对象最近距离:【"(rtos data 2 3)"】mm"))
(princ)
)
以上程序是引用“Z版主的”,在图二执行程序后如何才能显示图一的效果,请高手们指点,谢谢
页:
[1]