Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:crvthroughpline [2015/09/14] (current)
Line 1: Line 1:
 +====== Create a control points curve through a polyline ======
 +> **Developer:​** //​[[developer:​cplusplusplugins|C++]]//​
 +> **Summary:​** //​Demonstrates how to create a control points curve through a polyline.//
 +
 +===== Question =====
 +I have a polyline curve and I want to do what the **CurveThroughPolyline** does when "​Curvetype=ControlPoint"​ and I want to specify a degree. Is there an SDK function do to this?
 +
 +===== Answer =====
 +I don't believe there is an SDK function to do this. But writing your own function is not too difficult - see below.
 +
 +==== C++ ====
 +<code c++>
 +ON_NurbsCurve* RhControlPointsCurveThroughPolyline(
 +    const ON_Polyline&​ polyline, ​
 +    int degree
 +    )
 +{
 +  const int count = polyline.Count();​
 +  if( count < 2 )
 +    return 0;
 +
 +  degree = ( count <= degree) ? count - 1 : degree;
 +
 +  ON_NurbsCurve* curve = ON_NurbsCurve::​New();​
 +  if( curve )
 +  {
 +    bool rc = false;
 +    if( polyline.IsClosed() )
 +      rc = curve->​CreatePeriodicUniformNurbs( 3, degree + 1, count - 1, polyline );
 +    else
 +      rc = curve->​CreateClampedUniformNurbs( 3, degree + 1, count, polyline );
 +
 +    if( !rc )
 +    {
 +      delete curve;
 +      curve = 0;
 +    }
 +  }
 +
 +  return curve;
 +}
 +</​code>​
 +
 +\\
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/crvthroughpline.txt ยท Last modified: 2015/09/14 (external edit)