McNeel Wiki
Splitting Curves into Multiple Segments
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
DeveloperRhinoScript
SummaryDemonstrates how to split a curve into multiple segments using RhinoScript.

Question

I know that RhinoScript's SplitCurve function will split a curve into two pieces. But what if I need to split a curve into more than two pieces?

Answer

You can split a curve into multiple pieces by using the TrimCurve function. TrimCurve will trim a curve by removing portions of the curve outside of a specified interval. All you need to do is first divide the curve into the number of segments you want using DivideCurve. Then, loop through each division segment, create intervals from the results of CurveClosestPoint, and then trim the curve. For example:

  Option Explicit


  Sub CurveSplitter


    Const rhCurveObject = 4


    Dim sCurve
    sCurve = Rhino.GetObject("Select curve to split", rhCurveObject)
    If IsNull(sCurve) Then Exit Sub


    Dim nSegments
    nSegments = Rhino.GetInteger("Number of segments", 2, 2)
    If IsNull(nSegments) Then Exit Sub


    Dim aPoints
    aPoints = Rhino.DivideCurve(sCurve, nSegments)
    If Not IsArray(aPoints) Then Exit Sub


    Rhino.EnableRedraw False


    Dim i, t0, t1
    For i = 0 To UBound(aPoints) - 1
      t0 = Rhino.CurveClosestPoint(sCurve, aPoints(i))
      t1 = Rhino.CurveClosestPoint(sCurve, aPoints(i+1))
      Rhino.TrimCurve sCurve, Array(t0, t1), vbFalse
    Next


    Rhino.DeleteObject sCurve
    Rhino.EnableRedraw True


  End Sub

 

rename · changes · history · subscriptions · lost and found · references · file upload