McNeel Wiki
How To: Create a NURBS Curve from Control Points
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Rhino Labs

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

中文(简体)

 
.
SummaryDemonstrates two ways to create clamped ON_NurbsCurve from a set of control points.

C++ - Method 1

    CRhinoCommand::result CCommandTest::RunCommand(
            const CRhinoCommandContext& context )
    {
      ON_3dPointArray points;
      points.Append( ON_3dPoint(0, 0, 0) );
      points.Append( ON_3dPoint(0, 2, 0) );
      points.Append( ON_3dPoint(2, 4, 0) );
      points.Append( ON_3dPoint(4, 2, 0) );
      points.Append( ON_3dPoint(4, 0, 0) );


      ON_NurbsCurve* nc = ON_NurbsCurve::New(); 
      nc->CreateClampedUniformNurbs( 3, 4, points.Count(), points );


      if( nc->IsValid() )
      {
        context.m_doc.AddCurveObject( *nc );
        context.m_doc.Redraw();
      }


      RhinoApp().ActiveDoc()->Redraw();
      return CRhinoCommand::success;
    }

C++ - Method 2

    CRhinoCommand::result CCommandTest::RunCommand(
            const CRhinoCommandContext& context )
    {
      ON_3dPointArray points;
      points.Append( ON_3dPoint(0, 0, 0) );
      points.Append( ON_3dPoint(0, 2, 0) );
      points.Append( ON_3dPoint(2, 4, 0) );
      points.Append( ON_3dPoint(4, 2, 0) );
      points.Append( ON_3dPoint(4, 0, 0) );


      int dimension = 3;
      bool bIsRat = false;
      int order = 4;
      int cv_count = points.Count();


      ON_NurbsCurve* nc = ON_NurbsCurve::New(dimension, bIsRat, order, cv_count);
      if( !nc )
            return CRhinoCommand::failure;


      //Set CV points
      nc->ReserveCVCapacity( cv_count );
      for( int i = 0; i < points.Count(); i++ )
      {
            nc->SetCV(i, points[i] );
      }


      //Set Knots
      nc->ReserveKnotCapacity( order+cv_count-2 );
      ON_MakeClampedUniformKnotVector( order, cv_count, nc->m_knot );


      if( nc->IsValid() )
      {
        context.m_doc.AddCurveObject( *nc );
        context.m_doc.Redraw();
      }


      RhinoApp().ActiveDoc()->Redraw();
      return CRhinoCommand::success;
    }

VB.NET (Rhino 4) - Method 1

  Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext)_
    As RMA.Rhino.IRhinoCommand.result


      Dim CPoints As New List(Of On3dPoint)
      CPoints.Add(New On3dPoint(0, 0, 0))
      CPoints.Add(New On3dPoint(0, 2, 0))
      CPoints.Add(New On3dPoint(2, 4, 0))
      CPoints.Add(New On3dPoint(4, 2, 0))
      CPoints.Add(New On3dPoint(4, 0, 0))


      Dim dimension As Integer = 3
      Dim order As Integer = 4


      Dim nc As New OnNurbsCurve
      nc.CreateClampedUniformNurbs(dimension, order, CPoints.ToArray())


      If (nc.IsValid()) Then
            context.m_doc.AddCurveObject(nc)
            context.m_doc.Redraw()
      End If
      Return IRhinoCommand.result.success


  End Function

VB.NET (Rhino 4) - Method 2

  Public Overrides Function RunCommand(ByVal context As RMA.Rhino.IRhinoCommandContext)_
    As RMA.Rhino.IRhinoCommand.result


      Dim i As Integer
      Dim CPoints As New List(Of On3dPoint)
      CPoints.Add(New On3dPoint(0, 0, 0))
      CPoints.Add(New On3dPoint(0, 2, 0))
      CPoints.Add(New On3dPoint(2, 4, 0))
      CPoints.Add(New On3dPoint(4, 2, 0))
      CPoints.Add(New On3dPoint(4, 0, 0))


      Dim dimension As Integer = 3
      Dim bIsRational As Boolean = False
      Dim order As Integer = 4
      Dim cv_count As Integer = CPoints.Count()


      Dim nc As New OnNurbsCurve(dimension, bIsRational, order, cv_count)


      'Set CV Points
      nc.ReserveCVCapacity(cv_count)
      For i = 0 To cv_count - 1
            nc.SetCV(i, CPoints(i))
      Next


      'Set Knots
      nc.ReserveKnotCapacity(order + cv_count - 2)
      nc.MakeClampedUniformKnotVector()


      If (nc.IsValid()) Then
            context.m_doc.AddCurveObject(nc)
            context.m_doc.Redraw()
      End If
      Return IRhinoCommand.result.success


  End Function
Last Modified [10/19/2008] rename · changes · history · subscriptions · references · file upload