αдöߵĸlisp

(defun c:test ()
(vl-load-com)
(setq obj (car (entsel "\nSelect a Polyline: ")))
(MASSOC 10 (entget obj))
)
(defun massoc (key alist / x nlist)
(foreach x alist
(if (eq key (car x))
(setq nlist (cons (cdr x) nlist))
)
)
(reverse nlist)
)  



жǱպϵģ  

жǷպ:
(vlax-curve-isClosed Obj)  

 
 
 
(vla-IntersectWith obj1 obj2 mode) . 



ο:
SweepLine.lsp by Daniele Piazza.
This is a "SWEEPLINE algorithm to compute all intersection points of n line segments"
(Preparata & Shamos - Computational Geometry: an introduction) 
This is again academic code and should be used if you expect a huge number of lines to intersect and you are looking for all intersection points. (sweepline) should run in O(n*logn), but the shell sort in AutoLISP is too slow.


;;; Otherwise a greedy method like this is sufficient:
;;; O(n*2), exactly: O(n*(n-1))
;;; test each line with all other lines
;;; segments: ((p1 p2)(p1 p2)...)
(defun greedy-all-intersections (segments / seg1 rest seg2 pt pts)
(setq rest segments)
(foreach seg1 segments
(setq rest (cdr rest))
(foreach seg2 rest
(if (setq pt (inters (car seg1)(cadr seg1)(car seg2)(cadr seg2) T))
(setq pts (cons pt pts)))))
pts
)

Extensions:
It is possible to add bulged segments too by extending the data structure "segment" with (p1 p2 bulge) for curved segments and use a line-arc resp. arc-arc intersection method for those. Then a straight segment is still representable with (p1 p2) 







⽻ĳ

ڹѾľֱ߽λֿԱƴLISPARXҰæһ£м  
 

XDRX_API xdrx_getinters һ㶨һ

ܣ1.AcDbCurve()ʵĽ.
      2.һAcDbCurve()ʵһѡAcDbCurve()Ľ㡣
      3.һѡAcDbCurve()ʵĽ.
      4.һѡSS1еAcDbCurveʵѡSS2AcDbCurveʵĽ㡣
      
øʽ 1. (xdrx_getinters <ʵͼԪ1> <ʵͼԪ2> [չʽ])
          2. (xdrx_getinters <ʵͼԪ> <ѡ> [չʽ])
          2. (xdrx_getinters <ѡ> [չʽ])
          3. (xdrx_getinters <ѡ1> <ѡ2> [չʽ])
          4. (xdrx_getinters (...) <ʵ> [չʽ])
          5. (xdrx_getinters (...) <ѡ> [չʽ])
          6. (xdrx_getinters (...) (...) [չʽ])

˵1.AcDbCurve(AcDbLineAcDbArcAcDbCircleAcDbEllipseAcDbSpline
       AcDbPolyline(lwpolyline)㡣
     2.[չʽ]
       1
         0ʵ
         1һʵ
         2ڶʵ
         3: 
       ڵڶ(ѡ):
         0: ʵ
         1: 

ʾ 1. ߲ϣߵĽ
      (if (setq ss (ssget "x" (list (cons 8 (xdrx_getlyrname "")) '((0 . "line")))))
         (progn
             (setq intl (xdrx_getinters ss))
         )
      )
      
      2. ȡһߣȻཻ߽㡣
      (setq lyr (xdrx_getlyrname ""))
      (if (setq en (xdrx_entsel "\nȡһ<˳>:" (list (cons 8 lyr) '(0 . "line"))))
         (progn
            (xdrx_setentodb)
            (setq p1 (xdrx_getentdxf 10)
                  p2 (xdrx_getentdxf 11)
                  ss (ssget "f" p1 p2 (list (cons 8 lyr) '(0 . "line")))
            )
            (if (setq intl (xdrx_getinters (car en) ss))
               (progn
                  .....;;intlΪ
               )
            )
         )
      )          

      
 
 
 
 