Author Topic: Search of self-traverses LWPOLYLINE  (Read 4925 times)

0 Members and 1 Guest are viewing this topic.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Search of self-traverses LWPOLYLINE
« on: August 08, 2006, 05:59:02 AM »
If who that interfered with with self-traverses of selfcontained polylines, inform please the information.
Polylines have many the arc segments (thousand) and by hand-carry to find problem places very difficultly...
The idea or a search algorithm for self-traverses Is necessary for their elimination.

Beforehand THANK!

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Search of self-traverses LWPOLYLINE
« Reply #1 on: August 08, 2006, 08:45:52 AM »
Hi

Here's a routine which returns all self-intersection points of a lwpolyline, if it can help ...

Code: [Select]
((lambda (/ ent vtx lst ent rslt)
   (setq ent (car (entsel "\nSelect the pline: "))
vtx (mapcar
       '(lambda (pt)
  (trans
    (list (car pt) (cadr pt) (cdr (assoc 38 (entget ent))))
    ent
    0
  )
)
       (mapcar
'cdr
(vl-remove-if-not
   '(lambda (x) (= (car x) 10))
   (entget ent)
)
       )
     )
lst (vlax-invoke
       (vlax-ename->vla-object ent)
       'Explode
     )
   )
   (while (cdr lst)
     (repeat (1- (setq n (length lst)))
       (if
(setq int (vlax-invoke
     (car lst)
     'IntersectWith
     (nth (setq n (1- n)) lst)
     acExtendNone
   )
)
  (setq rslt (cons int rslt))
       )
     )
     (vla-delete (car lst))
     (setq lst (cdr lst))
   )
   (vla-delete (car lst))
   (setq
     rslt (vl-remove-if
    '(lambda (x) (vl-some '(lambda (y) (equal x y 1e-9)) vtx))
    rslt
  )
   )
 )
)

Edit : Take care of the behavior of IntersectWith method in UCS not parallel with the WCS.
« Last Edit: August 08, 2006, 08:55:34 AM by gile »
Speaking English as a French Frog

LE

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #2 on: August 08, 2006, 01:06:57 PM »
Hey Evgeniy;

Need more input - what it is the purpose for this routine?, a drawing sample , an image - etc. (or maybe just me)

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Search of self-traverses LWPOLYLINE
« Reply #3 on: August 09, 2006, 07:41:28 AM »
Hey Evgeniy;

Need more input - what it is the purpose for this routine?, a drawing sample , an image - etc. (or maybe just me)

This Lwpolyline have Self intersections...
« Last Edit: August 09, 2006, 07:43:13 AM by ElpanovEvgeniy »

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Search of self-traverses LWPOLYLINE
« Reply #4 on: August 09, 2006, 09:32:46 AM »
Sorry, I certainly didn't have understood what you meant with self intersections, I tried the routine I posted on your lwpolyline, it takes a while but don't return any intersection point.
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Search of self-traverses LWPOLYLINE
« Reply #5 on: August 09, 2006, 10:06:58 AM »
Sorry, I certainly didn't have understood what you meant with self intersections, I tried the routine I posted on your lwpolyline, it takes a while but don't return any intersection point.
Excuse, I have badly explained a problem...

LE

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #6 on: August 09, 2006, 10:41:25 AM »
This Lwpolyline have Self intersections...

I ran some tests and does not - how do you found that out?

Here is a very simple test (in your case for the complexity of the polyline it takes forever doing it in lisp)

Make a selection of the polyline, extract the number of coordinates (vertices) and do a self intersection using the same object (polyline) and extract the number of intersections if this number is greater than the vertices - it's self-intersect

Code: [Select]
;; return
;; T = self-intersect
;; nil = normal
(defun c:tst ()
(setq ename (car (entsel)))
(setq obj (vlax-ename->vla-object ename))
(setq ints (vlax-safearray->list
     (vlax-variant-value
       (vla-intersectwith obj obj acExtendNone))))

(> (/ (length ints) 3)
   (/ (length (vlax-get obj 'coordinates)) 2)))

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Search of self-traverses LWPOLYLINE
« Reply #7 on: August 09, 2006, 10:56:09 AM »
I ran some tests and does not - how do you found that out?

Here is a very simple test (in your case for the complexity of the polyline it takes forever doing it in lisp)

Make a selection of the polyline, extract the number of coordinates (vertices) and do a self intersection using the same object (polyline) and extract the number of intersections if this number is greater than the vertices - it's self-intersect

Code: [Select]
;; return
;; T = self-intersect
;; nil = normal
(defun c:tst ()
(setq ename (car (entsel)))
(setq obj (vlax-ename->vla-object ename))
(setq ints (vlax-safearray->list
     (vlax-variant-value
       (vla-intersectwith obj obj acExtendNone))))

(> (/ (length ints) 3)
   (/ (length (vlax-get obj 'coordinates)) 2)))

Code: [Select]
(/ (length ints) 3) = 1327
(/ (length (vlax-get obj 'coordinates)) 2) = 1898
Command: _region
Select objects: Specify opposite corner: 1 found

Select objects:
1 loop extracted.

1 loop rejected.
    Self intersections                     : 1 loop.


0 Regions created.

LE

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #8 on: August 09, 2006, 02:00:55 PM »
I need to look for some old code of mine.... I remember that I wrote a function for this, I thought what I posted was right.... (lately not true = excuse 12344 = age)  :lol:

LE

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #9 on: August 09, 2006, 02:14:34 PM »
Here is an old function - but for the type of complexity of your pline it will take a lot - so wait be patience and have a coffee:

Found here:
http://discussion.autodesk.com/thread.jspa?messageID=1118437

Code: [Select]
;;; sample by Luis Esquivel, December 17, 2001
;;; self-intersect
;;; return: T or nil
;;; note: you must pass a polyline or spline object, no error catching

(defun C:TEST (/ ent)
(lbx-self-intersect
(setq ent (car (entsel)))
)
)

(defun lbx-self-intersect (ent)
;;; / vla objname)
(vl-load-com)
(setq vla (vlax-ename->vla-object ent)
objname (vla-get-objectname vla)
)
(if (= "AcDbSpline" objname)
(progn
(if (safearray-value
(vlax-variant-value
(vla-intersectwith
vla
vla
acExtendNone
)
)
)
T
nil
)
)
(progn
(if (= :vlax-false (vla-get-closed vla))
(progn
(if (safearray-value
(setq intersections
(variant-value
(vla-intersectwith vla vla acExtendNone)
)
)
)
(apply
'/=
(list
(- (/ (length (vlax-safearray->list
(variant-value (vla-get-coordinates vla))
)
)
2
)
2
)
(/ (length (vlax-safearray->list intersections)) 3)
)
)
)
)
(if (safearray-value
(setq intersections
(variant-value
(vla-intersectwith vla vla acExtendNone)
)
)
)

(apply
'/=
(list
(/ (length (vlax-safearray->list
(variant-value (vla-get-coordinates vla))
)
)
2
)
(/ (length (vlax-safearray->list intersections)) 3)
)
)
)
)
)
)
)

LE

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #10 on: August 09, 2006, 07:15:18 PM »
Evgeniy;

What will be the purpose of this function/routine?

Do you want to select all the objects and generate a closed polyline?


Thanks.

chlh_jd

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #11 on: August 16, 2012, 04:26:35 PM »
Is this problem solved ?
I think Acad 'region' command  can't accept this Lwpolyline  , just like can't build the boundary though 'Bpoly' method  , but don't be sure .
Isn't there cross-itself points in it ? At least  I can not found now .

JOHNB

  • Guest
Re: Search of self-traverses LWPOLYLINE
« Reply #12 on: August 16, 2012, 06:08:55 PM »
Hi all,
I'm wondering if there is a way of correcting this problem with self intersecting polylines.
I have exploded the sample drawings polyline & then used overkill to remove duplicate objects, one found & erased.
I then recreated the poly by join - all - which works to make a polyline BUT it is still self intersecting.
Any help would be appreciated.
Thanks in advance
JohnB