Site Tools


Listing the Knot Vector of a NURBS Curve

Developer: RhinoScript
Summary: Demonstrates how to print the knot vector of NURBS curve using RhinoScript

Question

I notice that Rhino's List command will display the knot vector of a NURBs curve. How can I obtain the same information, using RhinoScript, that is displayed by this command.

Answer

The following RhinoScript sample demonstrates how to print the knot vector of a NURBs curve is a format similar to that of Rhino's List command.

 Option Explicit
 
 Sub ListKnotVector
 
   Dim curve : curve = Rhino.GetObject("Select curve", 4)
   If IsNull(curve) Then Exit Sub
 
   Dim knot : knot = Rhino.CurveKnots(curve)
   If Not IsArray(knot) Then
     Rhino.Print "NULL knot vector"
   End If
 
   ' order = degree + 1
   Dim order : order = Rhino.CurveDegree(curve) + 1
   If (order < 2) Then
     Rhino.Print "knot vector order < 2"
   End If
 
   Dim cv_count : cv_count = Rhino.CurvePointCount(curve)
   If (cv_count < order) Then
     Rhino.Print "knot vector cv_count < order"
   End If
 
   Dim knot_count, i, i0, mult
   If (order >= 2) And (cv_count >= order) And IsArray(knot) Then
     knot_count = order + cv_count - 2
     i = 0
     i0 = 0
     Rhino.Print "index, value, mult, delta"
     While (i < knot_count)
       mult = 1
       Do While (i + mult < knot_count) 
         If (i + mult < knot_count) Then
           If (knot(i) = knot(i+mult)) Then
             mult = mult + 1
           Else
             Exit Do
           End If
         Else
           Exit Do
         End If
       Loop
       If (i = 0) Then
         Rhino.Print CStr(i) & ", " & CStr(knot(i)) & ", " & CStr(mult)
       Else
         Rhino.Print CStr(i) & ", " & CStr(knot(i)) & ", " & CStr(mult) & ", " & CStr(knot(i)-knot(i0))
       End If
       i0 = i
       i = i + mult
     Wend
   End If
 
 End Sub  


developer/scriptsamples/listknotvector.txt ยท Last modified: 2015/12/04 by sandy