How to offset offset a self-intersecting polyline without trimming the crossing lines?

How to offset offset a self-intersecting polyline without trimming the crossing lines?

ltastan1
Contributor Contributor
3,800 Views
19 Replies
Message 1 of 20

How to offset offset a self-intersecting polyline without trimming the crossing lines?

ltastan1
Contributor
Contributor

Hello everyone,

When I offset a self-intersecting polyline, AutoCAD trims the offset where it crosses the original polyline. Currently, there isn't a system variable that I can set to turn off this trimming behavior. Is there a LISP routine that can offset a self-intersecting polyline without trimming the offset at the intersection points as shown in the attachment?

0 Likes
Accepted solutions (1)
3,801 Views
19 Replies
Replies (19)
Message 2 of 20

Kent1Cooper
Consultant
Consultant

I expect that is going to require BREAKing the original Polyline into two pieces at some vertex such that neither remaining piece is self-intersecting, then OFFSETting each piece, and JOINing the original back together and PEDIT / Multiple / Joining the Offset results together with a fuzz distance in case the Break was at a non-tangent change in direction [i.e. the Offset results don't meet].

 

In your example, any vertex would do.  But how complex do these things get?  There are certainly configurations in which some Break points would leave at least one portion still self-intersecting.  If that's a possible result, it may be possible to find a way for a routine to determine whether that happened, and try a different vertex.

Kent Cooper, AIA
Message 3 of 20

leeminardi
Mentor
Mentor

Offset creates geometry to one side or the other of a polyline.  Since AutoCAD does not support the ability to apply a local twist angle enabling the creation of something akin to a mobius strip I suggest creating an offset to  both sides and delete what you do not want and join what you keep.

lee.minardi
Message 4 of 20

Kent1Cooper
Consultant
Consultant

@leeminardi wrote:

... I suggest creating an offset to  both sides and delete what you do not want and join what you keep.


That doesn't give complete "coverage" of the desired path.  In this analagous situation, white is the original, red the result of Offsetting to one side, green to the other:

Kent1Cooper_0-1700998761026.png

If OFFSET's goal is a result in which every part is the same distance away from the original, it can't fill in those gaps, because the entire length of each missing part would be at incorrect distances from the original.

 

Kent Cooper, AIA
Message 5 of 20

leeminardi
Mentor
Mentor

@Kent1Cooper The OP provided the following:

leeminardi_2-1701012640125.png

After taking another look at the post I see that the main issue for the OP was choosing the wrong side for the offset and using "both" as I suggested  isn't necessary.  Filling the gaps using extend as neeeded and then join  provides the desired solution.  

 

lee.minardi
Message 6 of 20

j.palmeL29YX
Mentor
Mentor

To repair the "cryptic" result I'd go this way: 

 

 

 

Instead ot the lenghten command you also can use the extend command. 

IMO it is not worth the trouble to put these handfull steps into a macro or LISP, of course you can do it if it you want.

 

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 7 of 20

leeminardi
Mentor
Mentor

@j.palmeL29YX   What software do you use to make videos like the one you posted here?

 

lee.minardi
Message 8 of 20

ltastan1
Contributor
Contributor

It is possible to perform this offset operation manually in a few steps.  Actually, what I'm looking for is a LISP routine that can offset the self-intersecting polyline without trimming with a single click. I don't understand why AutoCAD hasn't defined this option as a system variable.

0 Likes
Message 9 of 20

Kent1Cooper
Consultant
Consultant

@j.palmeL29YX wrote:

.... Instead ot the lenghten command you also can use the extend command. ....


In many cases those would work, but there are lots of configurations in which it becomes a little more complex, particularly if a vertex with a change in direction falls inside the Offset gap, like the red result here:

Kent1Cooper_0-1701026445938.png

After Exploding the red resulting Polylines, for the Arc and the lower-left Line, Lengthen would need APParent-intersection Osnap, but that doesn't work, or Extend could be used, but only in Standard mode with its Edge option set to Extend.  Or Fillet with zero radius.

 

In the green situation, the lower-leftward Line and the longer Arc happen to be able to intersect [Extend with the same settings, or Fillet], but if the white arc segment were of smaller-enough radius [grip-edit its midpoint leftward], that intersection wouldn't exist, and it would need to be Filleted with a non-zero radius like the upper right corner.

 

Etc., etc.  I doubt a routine could be made to work under any geometric configuration, but if there are only limited possible relationships, maybe something could be worked out.  But I agree, it may not be worth trying to automate -- lots and lots of these could be handled manually in less time than it would take to come up with a routine.

Kent Cooper, AIA
Message 10 of 20

Kent1Cooper
Consultant
Consultant

@ltastan1 wrote:

.... I don't understand why AutoCAD hasn't defined this option as a system variable.


To suggest that, go >here<.

Kent Cooper, AIA
0 Likes
Message 11 of 20

ltastan1
Contributor
Contributor

The reason I require a LISP routine that offsets a self-intersecting polyline without trimming is specific to my needs. I've developed a LISP program that successfully generates 2D G code program for a selected polyline. However, for tool compensation, it must be capable of offsetting the polyline in the specified direction. If the polyline doesn't self-intersect, then there's no problem. However, if it does, the G code program cannot generate the correct codes.

0 Likes
Message 12 of 20

theilt20uae
Observer
Observer

Here are the steps on how to offset a self-intersecting polyline without trimming the crossing lines:

  1. Offset the polyline by the desired distance. This can be done using a variety of methods, such as the offset_polyline() function from the shapely library.
  2. Identify any self-intersections in the offset polyline. This can be done using a variety of methods, such as the self_intersect() function from the shapely library.
  3. For each self-intersection, create a new vertex at the intersection point. This can be done using the intersection() function from the shapely library.
  4. Update the offset polyline to include the new vertices. This can be done by appending the new vertices to the offset polyline array.

Here is an example of how to offset a self-intersecting polyline without trimming the crossing lines using the shapely library:

 

As you can see, the offset polyline now includes the new vertices at the intersection points. This means that the polyline has been offset by 0.5 units without trimming the crossing lines.

0 Likes
Message 13 of 20

Kent1Cooper
Consultant
Consultant

@theilt20uae wrote:

.... Here is an example ....


No example included.  While we wait to see it, I'll raise a question.  In the original example on this topic, and possibly in any self-intersecting Polyline Offset result, Step 2 would need to identify self-intersections in more than one resulting Polyline [three in their example, and depending on the original configuration, possibly a large number of them].  Since you also don't include any link to the "shapely library," I need to ask whether it can do that.

Kent Cooper, AIA
0 Likes
Message 14 of 20

Kent1Cooper
Consultant
Consultant

@bbcorhitter wrote:

....

(command "_.OFFSET" "_B" your_polyline "_")

....


[Acad2020 that I have here does not have that option.  I'll try in Acad2024 from elsewhere later.]

 

But doesn't that require a distance input between the "_.OFFSET" and the "_B"?

Kent Cooper, AIA
0 Likes
Message 15 of 20

leeminardi
Mentor
Mentor
Accepted solution

Here's a simple lisp program that will create a single polyline all to one side of a selfintersecting polyline.  You must select the polyline at a point of the loop.  For example, the green dot not the red dot.  It's best if the point specifed for the side is near the selection point.

 

leeminardi_0-1701709112298.png

 

(defun c:offset2 (/)
; creates an offset all to one side of a selfintersecting polyline  
  (setq	ent (entsel
	      "\nSelect polyline at point on self intersecting loop."
	    )
	p2  (getpoint "\nSpecify point to the side you want the offset."
	    )
	d   (getreal "\nSpecify offset distance: ")
	en1 (car ent)
	p1  (cadr ent)
  )
  (command "_break" en1 p1 "@")
  (setq en2 (entlast))
  (command "_offset" d en1 p2 "e")
  (setq en3 (entlast))
  (command "_offset" d en2 p2 "e")
  (setq en4 (entlast))
  (command "_join" en3 en4 "")
  (princ)
)

 

lee.minardi
Message 16 of 20

Kent1Cooper
Consultant
Consultant

That's the idea from Message 2.  A couple of suggestions:

Also re-JOIN the source en1 and en2 Polylines back together.

Go to the nearest vertex to the pick point for the Break, so that the Joined end results don't have an extra vertex at the pick point.  [That has the risk that if there's a non-tangent change in direction there, the Offset results won't touch at their ends, so a fuzz distance would be needed in the JOINing.]

 

@ltastan1 , would your originals ever self-intersect more than once?  Depending on the specifics and exactly where you pick, this approach would sometimes not have the desired result on such a Polyline.

Kent Cooper, AIA
Message 17 of 20

j.palmeL29YX
Mentor
Mentor

@ltastan1 - a question, back to the roots:

Where is your polyline coming from? What about the idea not to create a polyline and then offset this polyline, but from the beginning immediately draw two parallel curves (similar to the MLINE command, but including arc segements too)?
I found an old LISP "DLINE" (DoubleLine) - unfortunately still in german - which can do that. Perhaps it would be helpful for you ... ?

 

 

Jürgen Palme
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

Message 18 of 20

leeminardi
Mentor
Mentor

@Kent1Cooper wrote:

That's the idea from Message 2. 

But no code?  You're a much better LISP prgrammer than me so after a few days of not seeig any code I thought I would give it a try.

A couple of suggestions:

Also re-JOIN the source en1 and en2 Polylines back together.

You're right,  I didn't need to define en3 and en4 as en1 and en2 were avaialable!  

Go to the nearest vertex to the pick point for the Break, so that the Joined end results don't have an extra vertex at the pick point.  [That has the risk that if there's a non-tangent change in direction there, the Offset results won't touch at their ends, so a fuzz distance would be needed in the JOINing.]

But if you go to the nearest vertex you also run the risk of that vertex being on the other side of the self-intersection point.  A select point snapped to a vertex could cause a problem as the ends of the two offset polylines may not be coincident.  Perhaps osnap should be turned off during selection.

@ltastan1 , would your originals ever self-intersect more than once?  Depending on the specifics and exactly where you pick, this approach would sometimes not have the desired result on such a Polyline.

The "break" approach could be modified by asking for the user to identify mutiple loops if they exist.  


 

lee.minardi
Message 19 of 20

ltastan1
Contributor
Contributor

I don't have a chance to draw Polylines as Double Lines from the beginning since the drawings are already prepared. With a LISP routine, it might be possible to calculate the coordinates of each vertex for all entities in the polyline and then apply an offset, but this involves complex calculations, and it is really not easy.

0 Likes
Message 20 of 20

ltastan1
Contributor
Contributor

The original polyline has only one self-intersection point..

Leeminardi's "break" approach gives good results as long as the selected point is on the polyline loop. However, when I pick the point near the endpoints of the polyline, it doesn't provides the desired offset.

0 Likes