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:
thanks for any help!
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.
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?
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.
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.
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?
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.
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.
thank you so much for your help and the great work!