Polyline.BreakAtAngles Method, but with a rule based 'angle' input

Hi!
So I’ve been trying to make a code that cuts polylines at specific points based on the angle between consecutive lines. Meaning, I can define that everything below 15 degrees stays connected, but everything above gets split into separate joined polylines.

Now I found this: Polyline.BreakAtAngles Method and it does exactly that:

for crv in crvs:
    break_pl = rg.Polyline.BreakAtAngles(crv, math.radians(t))

The problem is that it specifically looks for a single number as the angle, and not a range/deviation or any if >= t statements etc.

Is there a way to make the same thing happen, but define that the polyline breaks when ever the angle >= t ?
This would solve the problem and make a much longer code obsolete.

Thank you!
Lev

Hi @l.zhitnik

This seems to work here. With the attached polyline, I get 2 new curves:
polyline.3dm (160.7 KB)

import rhinoscriptsyntax as rs
import math
from System.Drawing import Color
import random


def break_polyline():
    curve = rs.GetObject("sel polyline")
    if not curve:
        return
    crv = rs.coercecurve(curve)
    result, pl = crv.TryGetPolyline()
    if not result:
        return
    # break angle in degrees, angle of 180 means tangent
    t=120
    break_pl = pl.BreakAtAngles(math.radians(t))
    for c in break_pl:
        curve = rs.AddPolyline(c)
        r = random.randint(30,220)
        g = random.randint(30,220)
        b = random.randint(30,220)
        rs.ObjectColor(curve, Color.FromArgb(255, r,g,b))
break_polyline()
1 Like

It works here, breaks polylines at joints with angles less than the degree specified. However it is of somewhat limited usefulness IMO - as it only breaks at angles smaller than specified, and there is no possibility of breaking at angles larger than specified. If that were the case, it would be possible to create a range of breaks.

And beware if the angle of a particular joint is EXACTLY what you specify, it may or may not break because of fuzzy floating point math. There is no tolerance built into this function. So if you want to be sure it always breaks at or smaller than the angle you want, you probably need to feed it the angle plus a tiny tolerance.

Otherwise, it’s only a few lines of code to iterate along all the segments of the polyline in a loop, get the angle between and collect the breakpoints. The only difficulty is if the polyline is closed, you have to grab the first and last segments outside of the loop and compare those as well.

1 Like

Hi @l.zhitnik, below is an old script which does this, you can enter the break angle and get a preview of the points where the angles between consecutive polyline segments are >= the entered values. There is an option to either split or just add the points, works with multiple open or closed polylines…

SplitPolylinesAtAngle.py (5.7 KB)

_
c.

2 Likes