francesc 发表于 2022-7-5 20:35:12

多段线截取

如何知道多段线是否与自身相交。
非常感谢。

Lee Mac 发表于 2022-7-5 20:45:42

这里有一种方法:
;; Polyline Self-Intersection-Lee Mac
;; Returns T if the supplied LWPolyline intersects itself

(defun LM:polyselfintersect-p ( ent / lst obj )
   (setq obj (vlax-ename->vla-object ent)
         lst (mapcar '(lambda ( x ) (trans x ent 0)) (LM:groupbynum (vlax-get obj 'coordinates) 2))
   )
   (vl-some '(lambda ( x ) (not (vl-some '(lambda ( y ) (equal x y 1e-) lst)))
       (LM:groupbynum (vlax-invoke obj 'intersectwith obj acextendnone) 3)
   )
)

;; Group by Number-Lee Mac
;; Groups a list into a list of lists, each of length 'n'

(defun LM:groupbynum ( l n / r )
   (if l
       (cons
         (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
         (LM:groupbynum l n)
       )
   )
)

要测试的程序:
(defun c:test ( / ent )
   (if (setq ent (car (entsel)))
       (LM:polyselfintersect-p ent)
   )
)

francesc 发表于 2022-7-5 20:58:37

非常感谢李

hanhphuc 发表于 2022-7-5 21:02:36

 
李很好。LM:groupbynum

fabcad 发表于 2022-7-5 21:16:36

你好
 
非常好的程序,如果T,我们能在自相交处创建一个点吗?
 
谢谢,李,做得很好。

Stefan BMR 发表于 2022-7-5 21:19:07

Lee,如果多段线与顶点相交,则函数返回nil,但应为T。
一种方法是研究“intersectionwith”方法返回的每个点的曲线参数。
(mapcar
'(lambda (x) (vlax-curve-getparamatpoint ent x))
(LM:groupbynum (vlax-invoke obj 'intersectwith obj acextendnone) 3)
)

Lee Mac 发表于 2022-7-5 21:27:02

 
非常感谢。
 
 
当然
(defun c:test ( / ent lst obj sel )
   (if (setq sel (ssget "_+.:E:S" '((0 . "LWPOLYLINE"))))
       (progn
         (setq ent (ssname sel 0)
               obj (vlax-ename->vla-object ent)
               lst (mapcar '(lambda ( x ) (trans x ent 0)) (LM:groupbynum (vlax-get obj 'coordinates) 2))
         )
         (foreach int (LM:groupbynum (vlax-invoke obj 'intersectwith obj acextendnone) 3)
               (if (not (vl-some '(lambda ( vtx ) (equal int vtx 1e-) lst))
                   (entmake (list '(0 . "POINT") (cons 10 int)))
               )
         )
       )
   )
   (princ)
)

;; Group by Number-Lee Mac
;; Groups a list into a list of lists, each of length 'n'

(defun LM:groupbynum ( l n / r )
   (if l
       (cons
         (reverse (repeat n (setq r (cons (car l) r) l (cdr l)) r))
         (LM:groupbynum l n)
       )
   )
)
 
谢谢
 
 
好的,Stefan,我承认我没有考虑过这种特殊的可能性——不过,我不确定检查交点的曲线参数是否是可行的解决方案,例如,考虑以下多段线的交点参数:
对于上述情况,我收到三个具有以下参数的交点:
5

Stefan BMR 发表于 2022-7-5 21:41:44

我以为我已经全部检查过了,但显然没有。我也考虑过这种情况,但看起来我是按相反的顺序构建的。。。
页: [1]
查看完整版本: 多段线截取