Site Tools


Extracting Interpolated Curve Construction Points

Developer: RhinoScript
Summary: How to reverse engineer an interpolated curve using RhinoScript.

Question

Is it possible to obtain the original points used when creating an interpolated curve using Rhino's InterpCrv command or RhinoScript's AddInterpCurveEx method?

Answer

If the curve has a degree of 3, then the answer is yes. Just get the curve's knots, or knot vector, and then evaluate each knot value.

Example

The following example demonstrates how to extract an interpolated curve's original construction points.

   Function ExtractInterpCrvPoints(curve)
 
   ' local variables
   Dim points(), knots, i
 
   ' default result
   ExtractInterpCrvPoints = Null
 
   ' verify the curve
   If Not IsNull(curve) And Rhino.IsCurve(curve) Then
 
     ' verify the degree of the curve
     If Rhino.CurveDegree(curve) = 3 Then
 
       ' get the curve's knots
       knots = Rhino.CurveKnots(curve)
 
       ' verify the curve's knots
       If IsArray(knots) Then
 
         ' evaluate the curve at each knot value      
         ReDim points(UBound(knots))
         For i = 0 To UBound(knots)
           points(i) = Rhino.EvaluateCurve(curve, knots(i))
         Next
 
         ' cull any duplicate points
         ExtractInterpCrvPoints = Rhino.CullDuplicatePoints(points)
 
       End If
 
     End If
 
   End If
 
 End Function


developer/scriptsamples/extractinterpcrvpoints.txt ยท Last modified: 2015/09/14 (external edit)