# Divide polyline in sections of equal angle sum

Hi everyone,

I am having trouble dividing a polyline into segments with equal angle sum.( the angle is measured in the XY plane) This is what I want to do:

For ccw curves the method I used seems to work nicely, but sadly it falls apart as soon as the curve bends cw or in both ways:

curve_divide_angle_sum.gh (35.1 KB)

thanks for any help!

Edit:

to clarify unless the angle sum of the section is larger than the specified value, ccw and cw rotations should cancel out:

Sorry, but I donât get it.

Do you want to begin at the start point of the polyline, rotate a delta amount in clockwise or counter-clockwise direction - following the polyline -, and split it there, then repeat the previous steps - incrementing delta - until the end is reached?

I want to split the curve every time when the angle sum of the current section is greater than a given value. Image the curve drawn on a sheet of paper and you move a matchbox car along it with your thumb and index finger touching the left and right side of the car at all times. Presumably you can twist your arm 360Â° â Where are the points where you have to let go? Does it make sense?

Why are there missing segments (gaps) in your results?

You added this clarification after I was well alongâŚ I saw this in your code but ignored it until I was finished (the group to ânormalize in range (-1 to 1) and subtract ccw anglesâ). That group can easily be added back. Anemone loop in yellow group.

This probably needs more time to verify since some of the results for ânon-convexâ donât look correct.

curve_divide_angle_sum_2021_Jul28a.gh (57.0 KB)

P.S. This version restores your group to ânormalize in range (-1 to 1) and subtract ccw anglesâ, though Iâm still not sure about the ânon-convexâ polyline?

curve_divide_angle_sum_2021_Jul28b.gh (57.7 KB)

1 Like

I believe this version is better. I created a separate GH model to test my understanding of angles with regard to âleft turnsâ vs. âright turnsâ and ended up rotating the first segment 90 degrees, then using the Dot Product of that and the second segment to determine plus or minus.

Oh yeah, and using absolute value (expression âabs(x)â) when comparing to the target angle.

curve_divide_angle_sum_2021_Jul28c.gh (55.5 KB)

P.S. As a test, you can copy the âangles between segmentsâ group and apply it to the grafted list of segments at the end. Negative numbers are âleft turnsâ (the helix, CCW), positive numbers are CW.

curve_divide_angle_sum_2021_Jul28c2.gh (55.9 KB)

Using the ânon-convexâ spiral, this test does not validate the algorithmâŚ

P.P.S. I can feel an off-by-one error in the Anemone loop, causing the terminating angle to be ignored?

1 Like

thank you very much for the help. I am currently trying to integrate your solution into my larger script and it is already better. I was wondering though for the âgummy bearâ polyline, shouldnât be all the seams over top of each other if you select 360Â°? Each layer is a deformed circle and it shouldnât matter how you go around the circle if you get where you started you have turned 360Â°

edit: forget that
the last image in first post shows it does not work like that

There isnât perfect alignment every 360 degrees, in either curve (helix or âgummy bearâ). The path lengths vary each time around, yet segment lengths are similar, so they donât match up. You can enable preview on the Disc (Discontinuity) component to see all the points.

For the same reason, angles donât add up to the âangle sumâ target either, so when the sum is greater, the sum resets to zero. In that process, I believe one angle is being skipped each time.

Iâve stared at it too long and donât have a fix. Not even sure about my validation. Break time!

This one looks correct to me. The Anemone loop didnât change but I had to rebuild the polyline to get the correct number of segments from the original ânon-convexâ polyline. And a few other changesâŚ

Some of the resulting polyline fragments have only one segment because some angles are greater than the target. Others are quite long. There is a validation group at the bottom, not shown in this image.

curve_divide_angle_sum_2021_Jul28e.gh (68.2 KB)

3 Likes

NOTE: In the struggle to get code working, some decisions are made in the interest of expediency that should be factored out later. For example:

• The ânon-convexâ curve is reparameterized before the Stream Filter while the helix was not. At some point, this difference broke the code so I added reparameterize in three places where it now doesnât need to be.

• Insert Items is a data matching thing that could be handled differently, but itâs OK.

• The âangles between segments, left and right turns cancelâ group can be clustered as PolyAngle since itâs used again later in the âValidationâ group.

curve_divide_angle_sum_2021_Jul29a.gh (58.4 KB)

3 Likes

thank you so much for your help and the great work!