Transform line into serpentine line

Transform line into serpentine line

Anonymous
Not applicable
3,332 Views
10 Replies
Message 1 of 11

Transform line into serpentine line

Anonymous
Not applicable

Hi all, 

 

I'm currently learning how to make a LSP, and I'm in the middle of getting familiar with the coding environment and variables. 

My goal is to make a lisp that takes a polygon rectangle and transforms it into a serpentine line as shown below. I think for starters, i'll probably try to transform a polyline into an arc or a spline with a fixed radius, and then from there try to figure out how to turn a polygon into a serpentine polygon.

 

If you guys have any suggestions as to how to tackle this piece of code, it would be greatly appreciated. Also, if you guys have any resources for learning LSP and/or things I should look up, that would also be greatly appreciated as I start learning lisp coding. 

 

Thanks!

 

-jesse

serpentine_example.png

 

 

 

0 Likes
Accepted solutions (1)
3,333 Views
10 Replies
Replies (10)
Message 2 of 11

Kent1Cooper
Consultant
Consultant

Is that image supposed to be before on the right and after on the left?  The wording of the description sounds sort of like that, because the left is clearly more "serpentine" than the right.  But the right has two rows of two columns of squares with a single overall perimeter shape, whereas the left has two rows and four  columns, without  anything overall around the edge.  What's the relationship?

 

As for learning resources, do some Searching of this Forum for similar questions -- you'll find a great many suggestions.

Kent Cooper, AIA
0 Likes
Message 3 of 11

Anonymous
Not applicable

Yes, your assumption is correct.

 

The endgoal is to translate any arrangement of polygons into a serpentine line; the drawn polygons are just examples of things I would like to translate into a serpentine shape. The only reason that they're there is as a before-after thing, as you correctly assumed. 

 

If there's anything else I can do to clarify my question do please let me know.

 

Thanks!

 

-jesse 

0 Likes
Message 4 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

...

If there's anything else I can do to clarify my question do please let me know.

....


 

You can post an image or sample drawing showing the actual relationship between an "arrangement of polygons" and the "serpentine line" that should result from it, overlaid at the same position and the same size.  It's not at all clear to me how  the red part can result from the white part, or even whether that's your intent -- the spacings between red shapes are different from the spacings between white squares, I can't find a way to relate the white Circles [not in the image, but in the .dwg file] to the white squares [e.g. center-to-center spacing doesn't match anything about square size or spacing], etc.  In other words, what did you start from to get the red shapes?  What do you end up with if you do the same process from the white squares?  What becomes of the outer white perimeter shape?

 

Also, if the white squares and perimeter shape are real starting conditions, none of that is polygons -- they're all made up of one- and two-segment overlapping pieces.  That would make it very difficult for a routine to figure out what to do with what.

Kent Cooper, AIA
0 Likes
Message 5 of 11

Kent1Cooper
Consultant
Consultant
Accepted solution

Meanwhile, since you used the word "serpentine," SNAKE.lsp [available >here<] can do these kinds of conversions [white is before, all the same, red after with varying settings], if such a thing can serve your purpose:

Snake.PNG

Kent Cooper, AIA
0 Likes
Message 6 of 11

ronjonp
Mentor
Mentor

Maybe a spline or 'fit' polyline is what you need?

image.png

0 Likes
Message 7 of 11

Anonymous
Not applicable

I overlapped the lines to try and show the relationship more clearly in the attached dwg. Hopefully that helps a bit.

 

I think that snake LSP is a good starting point for what I'm looking for. The only two things that are missing from that LSP are a user defined radius/arc angle and a user defined snake interval width. I'd have to change the width anyways because I'm working in microns. 

 

 

Thank you very much for you help! Voted as solution. 

0 Likes
Message 8 of 11

Kent1Cooper
Consultant
Consultant

Well that makes it a little clearer.  It seems the red outlines in your first image are not themselves the goal, but the "pathways" between  them.

 

The arc halves of your pre-widened S-curves swing through a little more than 180 degrees, and not by any obvious [to me] "clean" amount.  I think it would be easy enough to come up with something to make the equivalent S from a straight thing [whether Polyline or Line] if the curves were half-circles, but since they're not, what determines their degree of curvature?  Or should  they be half-circles?

 

Also, the top left one in the drawing has the ends of the green S rotated somewhat off  the red line, but the one below has them touching  the red lines.  What's the criterion for that kind of thing?

Kent Cooper, AIA
0 Likes
Message 9 of 11

Kent1Cooper
Consultant
Consultant

@Kent1Cooper wrote:

....  I think it would be easy enough to come up with something to make the equivalent S from a straight thing [whether Polyline or Line] if the curves were half-circles, ....


 

For instance:

(vl-load-com); if needed
(defun C:SMLL ; = S-curve Match Line Length (/ ent startpt endpt midpt rad) (setq ent (car (entsel "\nLine or straight-line-only Polyline: ")) startpt (vlax-curve-getStartPoint ent) endpt (vlax-curve-getEndPoint ent) midpt (mapcar '/ (mapcar '+ startpt endpt) '(2 2 2)) rad (/ (distance startpt endpt) pi) ) (command "_.pline" "_none" (polar midpt (angle startpt endpt) rad) "_width" 0 0 ; just in case "_arc" "_c" "_none" (polar midpt (angle startpt endpt) (/ rad 2)) "_none" midpt "_none" (polar midpt (angle endpt startpt) rad) "" ); command (princ) ); defun

[A "straight-line-only Polyline" could be of more than one segment, as long as it doesn't do something like double back on itself.  It would draw an S-curve of incorrect size on one like that, or on selection of all kinds of other objects, but could be made to restrict the selection to appropriate things only, if needed.]

 

Kent Cooper, AIA
0 Likes
Message 10 of 11

Anonymous
Not applicable

The half-circles were drawn like that intentionally. My end goal is to create serpentine/snake lines from a polyline where I can control the curvature, i.e, creating arcs greater or less than 180°.  The one thing I haven't quite figured out yet is how I can control the curvature of the arc precisely...i have to draw them by hand until I roughly get to my desired angle. 

 

I will continue to play around with the code you've sent me. Thank you very much! 

0 Likes
Message 11 of 11

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....  The one thing I haven't quite figured out yet is how I can control the curvature of the arc precisely...i have to draw them by hand until I roughly get to my desired angle. ….


 

Unfortunately, until you can come up with a way of defining that desired angle with some definitive criteria, I don't think you'll be able to get a routine to draw it for you.

Kent Cooper, AIA
0 Likes