Determining the overlap of edges

Determining the overlap of edges

saitoib
Advocate Advocate
1,116 Views
16 Replies
Message 1 of 17

Determining the overlap of edges

saitoib
Advocate
Advocate

Hi all.
Thank you very much for your help.

 

>rectangle 0,0 100,100
>rectangle 100,0 100,90

 

In the case of a rectangular polyline like the one above, is it possible to get the coordinates of both ends of the overlapping edges, (100,0)(100,90)?

 

Thank you.

Saitoib
0 Likes
Accepted solutions (1)
1,117 Views
16 Replies
Replies (16)
Message 2 of 17

JamesMaeding
Advisor
Advisor

@saitoib 

Sure, comparing geometry for adjacent segments is common.

You can try to play that simple, and compare every polygon against every other,  but that created "n*n" loops, which is really inefficient. The better thing is to number the shapes (rectangles or whatever), make a list of segments with shape number, make a list of bounding boxes for them, sort the bounding box list, and use that sorted list to quickly narrow down if a given segment overlaps with others.

Recently, I realized the better way is to make a "k-d" tree of the bounding boxes, so you can find overlapping stuff  essentially for free. Not totally free, but enough to be called free for a couple million shapes.

Like I said, simple question, deep rabbit hole.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 3 of 17

Kent1Cooper
Consultant
Consultant

@saitoib wrote:

....

>rectangle 100,0 100,90

....


Is that really what you mean?  That would be a no-area "rectangle" that looks like a Line.

Kent Cooper, AIA
0 Likes
Message 4 of 17

Sea-Haven
Mentor
Mentor
Accepted solution

If you meant 0,0 100,100 and 0,0 100,90 then could look at VL intersectwith method make a selection set and compare elements removing from selection set after checked. 

 

(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
Message 5 of 17

JamesMaeding
Advisor
Advisor

@Sea-Haven 

I am always amazed at the clever approaches people find built into acad.

God idea.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 6 of 17

Sea-Haven
Mentor
Mentor

That is the ultimate help "God idea."

Message 7 of 17

saitoib
Advocate
Advocate

Oh, sorry.
>rectangle 100,0 150,90
This was the correct.

Saitoib
0 Likes
Message 8 of 17

saitoib
Advocate
Advocate

I didn't know there was such a command.
I solved it.
Thank you very much.

Saitoib
0 Likes
Message 9 of 17

JamesMaeding
Advisor
Advisor

@Sea-Haven 

"Christian" slip?

ha ha


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 10 of 17

Sea-Haven
Mentor
Mentor

A good idea is to post your solution may be useful for some one else, often the code is improved also.

0 Likes
Message 11 of 17

saitoib
Advocate
Advocate

I was able to solve the problem with the following code.
Thank you very much.

;; Find the intersection of two objects.
(defun c:intersection (/ obj1 obj2 intpt)
	(setq obj1 (vlax-ename->vla-object (car (entsel))))
	(setq obj2 (vlax-ename->vla-object (car (entsel))))	  
	(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
)

 

Saitoib
0 Likes
Message 12 of 17

JamesMaeding
Advisor
Advisor

@saitoib 

To what tolerance?

You see, things like "overlap" sound simple, but get very specific very fast in real life.

Also, when you deal with thousandsof lines, maybe to detect duplicate linework and delete it, you need something up front to narrow down what linework could possibly overlap another. That final "intersection" test is expensive, so you can't run each entity against all others, then the next against all others, then the next...that is n squared loops.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 13 of 17

ronjonp
Mentor
Mentor

@saitoib wrote:

I was able to solve the problem with the following code.
Thank you very much.

;; Find the intersection of two objects.
(defun c:intersection (/ obj1 obj2 intpt)
	(setq obj1 (vlax-ename->vla-object (car (entsel))))
	(setq obj2 (vlax-ename->vla-object (car (entsel))))	  
	(setq intpt (vlax-invoke obj2 'intersectWith obj1 acExtendThisEntity))
)

 


Wouldn't you want to use acExtendNone rather than acExtendThisEntity ?

0 Likes
Message 14 of 17

saitoib
Advocate
Advocate
 To JamesMaeding

In my case, I limit two objects to check for duplicates, so I think I can solve the problem using the method taught me.

 

To ronjonp

Indeed, acExtendNone seems to be a better choice.
I will try it.


Thank you very much for your help.

Saitoib
0 Likes
Message 15 of 17

Sea-Haven
Mentor
Mentor

There are 4 options for the extend bit you can use also 0 1 2 3 if I remember correct, it was just copied out of some code and often need to change the extend option to make it work.

0 Likes
Message 16 of 17

JamesMaeding
Advisor
Advisor

@saitoib 

Two objects? I feel like that teacher in original Willy Wonka movie "Nobody opens just two!".

You could just grab the vertex coords and compare to see if they match.

It sounds like you are new to lisp, and got a rather fancy answer to a question you did not explain well enough. We are expecting multiple entities to test.

The nice thing about "hand testing" the coords is you get tolerance control.

What if they are 0.001 apart? Dealing with those issues are what make real programs robust.


internal protected virtual unsafe Human() : mostlyHarmless
I'm just here for the Shelties

0 Likes
Message 17 of 17

saitoib
Advocate
Advocate

Understood.
I will try to work with intersectWith for now, keeping the error in mind.

 

Thank you for your suggestion.

Saitoib
0 Likes