RhinoCommon Curve.Fit with degree 1 curves

Hi all,

Noticed this while trying to script something like FitCrv to work on a polyline. The Curve class has a Fit() method that is inherited by other subclasses, including PolylineCurve and NurbsCurve. The problem happens when I try and run the Fit() method directly on a degree 1 input curve - it fails in that the returned curve is identical to the input curve…

The scriptlet below returns a NURBS curve of degree 1 identical to the original polyline curve (SelDup selects it), despite the fact that I asked it to fit to degree 3…

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

pl_ID=rs.GetObject("Select polyline curve to fit",4,True)
if pl_ID:
    plc=rs.coercecurve(pl_ID)
    #degree 3, fit tolerance 0.1, no kinks preserved
    result=plc.Fit(3,0.1,0)
    if result: sc.doc.Objects.AddCurve(result)
sc.doc.Views.Redraw()

Converting the polyline curve to a NURBS curve of degree 1 first does not change things…

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

pl_ID=rs.GetObject("Select polyline curve to fit",4,True)
if pl_ID:
    plc=rs.coercecurve(pl_ID)
    nc=plc.ToNurbsCurve()
    result=nc.Fit(3,0.1,0)
    if result: sc.doc.Objects.AddCurve(result)
sc.doc.Views.Redraw()

The only thing that works is to convert first to NURBS and then increase the degree.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

pl_ID=rs.GetObject("Select polyline curve to fit",4,True)
if pl_ID:
    plc=rs.coercecurve(pl_ID)
    nc=plc.ToNurbsCurve()
    nc.IncreaseDegree(2) #anything larger than 1 works
    result=nc.Fit(3,0.1,0)
    if result: sc.doc.Objects.AddCurve(result)
sc.doc.Views.Redraw()

The above works as it should (IMO).

So, either there is a bug in the method, or the input degree limitation needs to be expressed in the api guide. The guide only talks about the return degree of Fit() being bigger than 1, not the input.

–Mitch

Hi @Helvetosaur,

The degree of the returned curve must be greater than 1.

http://developer.rhino3d.com/api/RhinoCommon/html/M_Rhino_Geometry_Curve_Fit.htm

– Dale

Yes, except it’s not… Try with a polyline as input argument. --Mitch

Sigh…

https://mcneel.myjetbrains.com/youtrack/issue/RH-42326

Your temporary fix of increasing the degree is an appropriate fix.

– Dale

RH-42326 is fixed in the latest BETA