# Differences

This shows you the differences between two versions of the page.

 — developer:scriptsamples:divideequidistance [2015/09/14] (current) Line 1: Line 1: + ====== Divide a curve using equi-distance points ====== + > **Developer:​** //​[[developer:​rhinoscript|RhinoScript]]//​ + > **Summary:​** //​Demonstrates equi-distance curve division using RhinoScript//​ + + =====Summary===== + Rhino'​s Divide command divides a curve based on arc length, or the distance along the curve between two points. This [[developer:​rhinoscript|RhinoScript]] sample divides a curve based on the distance (linear) between points. + + {{:​legacy:​en:​EquiDistantDivide.png}} + + + ​Option Explicit + + '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​ ''''''''''  ​ + '​ Description + ' ​  ​Divides a curve based on the linear distance between points. + '​ + Sub DivideCurveEquiDistant + + Dim crv + crv = Rhino.GetObject("​Select curve to divide",​ 4, True) + If IsNull(crv) Then Exit Sub + + Dim crv_length + ​crv_length = Rhino.CurveLength(crv) + + Dim length + ​length = Rhino.GetReal("​Curve length is " & CStr(crv_length) & ". Division length",​ 1.0) + If Not IsNumeric(length) Then Exit Sub + + If (crv_length < length) Then + ​Rhino.Print "​Specified divison length exceeds curve length."​ + Exit Sub + End If    ​ + + ​Rhino.EnableRedraw False  ​ + + Dim dom, t, pt + dom = Rhino.CurveDomain(crv) + t = dom(0) + pt = Rhino.EvaluateCurve(crv,​ t) + ​Rhino.AddPoint pt + + Dim bDone: bDone = False + While (bDone = False) + t = EquiDistantParameter(crv,​ t, length) + If IsNull(t) Then + bDone = True + Else + pt = Rhino.EvaluateCurve(crv,​ t) + ​Rhino.AddPoint pt + End If + Wend + + ​Rhino.EnableRedraw True + + End Sub + + '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''​ + '​ Description + ' ​  Finds the parameter on a curve that is a specified + ' ​  ​linear distance from a known parameter. + '​ + ​Function EquiDistantParameter(crv,​ t, length) + + ​EquiDistantParameter = Null + + Dim pt + pt = Rhino.EvaluateCurve(crv,​ t) + + Dim sphere + ​sphere = Rhino.AddSphere(pt,​ length) + + Dim csx + csx = Rhino.CurveSurfaceIntersection(crv,​ sphere) + + ​Rhino.DeleteObject sphere + If Not IsArray(csx) Then Exit Function + + Dim i + For i = 0 To UBound(csx) + If csx(i,0) = 1 Then + If (csx(i,5) > t) Then + ​EquiDistantParameter = csx(i,5) + Exit Function + End If + End If + Next + + End Function  ​ + + ​ + + \\ + + + {{tag>​Developer RhinoScript}}