Unable to use NurbsCurve.SetGrevillePoints()

Hi all, I am creating a tool and it uses GrevillePoints to better edit the NurbsCurve.

Below is a simplified snippet of what I am trying to do.

            var pt1 = new Point3d(1, 2, 0);
            var pt2 = new Point3d(2, 3, 0);
            var pt3 = new Point3d(5, 12, 0);
            var pt4 = new Point3d(12, 3, 0);
            var dynamic_points = new[] { pt1, pt2, pt3, pt4 };
            var curve = new NurbsCurve(3, 4);
             curve.SetGrevillePoints(dynamic_points); //always return with false

curve.SetGrevillePoints(dynamic_points);

the above line fails to execute. What am I missing here?

I have read the below thread, but I am still unable to grasp how to better manipulate a curve with Edit / Greville Points in RhinoCommon.

@menno
@TomTom

Hi Wiley

It seems to work if we set CVs and knots first. (Rhino 6 here)

Python sample:

import Rhino
import scriptcontext

def main():
    cu = Rhino.Geometry.NurbsCurve( 3, 4 )
    cu.Points[ 0 ] = Rhino.Geometry.ControlPoint( 0, 0, 0 )
    cu.Points[ 1 ] = Rhino.Geometry.ControlPoint( 0, 1, 0 )
    cu.Points[ 2 ] = Rhino.Geometry.ControlPoint( 0, 2, 0 )
    cu.Points[ 3 ] = Rhino.Geometry.ControlPoint( 0, 3, 0 )
    cu.Knots.CreateUniformKnots( 1 )
    print( cu.SetGrevillePoints( [
        Rhino.Geometry.Point3d( 1, 2, 0 ),
        Rhino.Geometry.Point3d( 2, 3, 0 ),
        Rhino.Geometry.Point3d( 5, 12, 0 ),
        Rhino.Geometry.Point3d( 12, 3, 0 ) ] ) )
    scriptcontext.doc.Objects.AddCurve( cu )
    scriptcontext.doc.Views.Redraw()
    
main()

HTH

1 Like

Thank you @emilio !
It worked like a charm!

For those who are wondering, this is how it is done in C#

            var dynamic_points = new List<Point3d>
            {
             new Point3d(1, 2, 0),
            new Point3d(2, 3, 0),
            new Point3d(1, 12, 0),
            new Point3d(5, 3, 0),
            };
            var curve = new NurbsCurve(3, dynamic_points.Count);
            for (int i = 0; i < dynamic_points.Count; i++)
                curve.Points[i] = new ControlPoint(0, i, 0);
            curve.Knots.CreateUniformKnots(1);
            curve.SetGrevillePoints(dynamic_points);
1 Like

The Greville points are evaluated at certain knot values. Without knots, you’re unable to calculate the Greville parameters, or set Greville points.

2 Likes