Converting curves to straight line segments

how to convert a closed curve into equal length straight lines. the vertices between lines all to lie on the source curve. the angle between lines can vary, as can the actual length; but i’d like the length of each straight line segment to be identical. ideally i’d like to be able to vary the number of the straight lines, and see what different lengths resulted. the source closed curve is a fix. using the ‘points along a curve’ technique does not work as it yields different length straight line elements depending on the local radius of the source curve.

Hi Nic- if you use Convert, with min and max lengths set the same and Angle at zero, it will do pretty well at making same length segments.

-Pascal

1 Like

Hey Pascal,
I can’t get convert to do this for me, I still get big variations in segment length with min and max set the same.
This seems like something for grasshopper, as it would be easier to show results with instant feedback with sliders.
Kind of a tricky one to solve manually. Maybe this is a good one for ArrayCurvePlus but I can’t get that plug in to work for me currently.

hi pascal,

many thanks for your thoughts. unfortunately i’m getting quite large variations in line segment length. i’m trying to establish a curtain wall geometry with identical size glazed units.

nic

hi carvecream,

i’m pretty new to rhino, having been using microstation for many years. i could solve manually by tracking round with fixed length lines from one point to another, pivoting as i go, but would be unlikely to meet up neatly at the start. grasshopper looks incredibly powerful; but a big step up in learning. guess i’ll have to take the plunge…

nic

Nic, RhinoScript has a built in function for this - DivideCurveEquidistant . Should be easy enough to implement as a script. Hang on a bit…

Try this -
DivideCurveEquidistant (2).zip (522 Bytes)

it’s a RhinoScript, but this is probably perfectly possible in Python as well. To use this script, unzip, then drag and drop it onto an open V5 Rhino, then use the ‘command’ (actually an alias that runs the script)

DivideCurveEquidistant

Does that do what you need?

Here’s a Python version - DivideCurveEquidistant.py (559 Bytes)

-Pascal

hi pascal,

very many thanks; that script worked perfectly. a couple of iterations of length, and the beginning and end met precisely.

thanks again.

nic

Hi Nic
Try the below python script. The red curve has the same length of the start curve.o
Ciao Vittorio

import rhinoscriptsyntax as rs
import scriptcontext as sc
def DivideCurveEq():    
    if sc.sticky.has_key("OldCrvDivLength"):
        oldLength = sc.sticky["OldCrvDivLength"]
    else: oldLength = 1    
    crv = rs.GetObject("Select a curve.",4, True)
    if not crv: return
    lun_crv=rs.CurveLength(crv)
    length = rs.GetReal("Set segment length",oldLength)    
    if not length: return
    sc.sticky["OldCrvDivLength"] = length
    points=rs.DivideCurveEquidistant(crv,length)    
    np= len(points)
    rs.EnableRedraw(False)        
    dmax=0.0001
    dist=1    
    len_crv=rs.CurveLength(crv)
    
    while dist>dmax:
        delta_length=dist/(np+1)
        new_length=length+delta_length   
        points=rs.DivideCurveEquidistant(crv,new_length,False,True)
        ps=points[0]
        pe=points[-1]               
        new_dist=rs.Distance(ps,pe)        
        length=new_length
        dist=new_dist       
        
    points[-1]=points[0]
    pl=rs.AddPolyline(points)
    cen,err=rs.CurveAreaCentroid(crv)
    pl_length=rs.CurveLength(pl)
    rap=lun_crv/pl_length
    nc=rs.ScaleObject(pl,cen,(rap,rap,rap),True)
    rs.ObjectColor(nc,(255,0,0))
    rs.EnableRedraw(True)
        
if __name__ == '__main__':
    DivideCurveEq()

hi vittorio,

many thanks for offering up a solution. i ended up using the .py file that pascal sent through. i tried using yours as well because i noticed your version of the script was longer and thought it might have additional features. tried pasting your text into an .rtf file and re-suffixing it as .py but rhino didn’t seem to like it.

but thanks for your help.

nic

Hi nic- here’s a slightly friendlier py script (lets you set the length while curve selection is happening, instead of sequentially). I suppose multi curve selection would be the next thing, right?

DivideCurveEquidistant_2.py (1.5 KB)

-Pascal

Hi Nic
you must use the command EditPythonScript, copy and paste the file in the editor and save the file with a name
Ciao Vittorio

Thanks Pascal! Very handy.

hi vittorio

yes, that worked really well; and it adjusts the length to fit the source curve exactly, perfect.

very many thanks for your help.

nic