@Helvetosaur wrote:
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
Posts: 1
Participants: 1