Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:addnurbscurve [2015/09/14] (current)
Line 1: Line 1:
 +======Create a NURBS Curve from Control Points======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates two ways to create clamped ON_NurbsCurve from a set of control points.//
 +
 +{{:​legacy:​en:​nc_example.PNG}}
 +
 +=====Method 1=====
 +
 +==== C++ ====
 +<code c++>
 +  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;​
 +  }
 +</​code>​
 +
 +=====Method 2=====
 +
 +==== C++ ====
 +<code c++>
 +  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;​
 +  }
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/addnurbscurve.txt ยท Last modified: 2015/09/14 (external edit)