Here's how I do it
- make the curve
a. create curve object (dimension, rational flag (does it have weights), degree of curve +1, how many control points do you have)
ON_NurbsCurve thisCurve(3, false, order, controlPoints.size());
b. add control points to curve
for(int i = 0; i <controlPoints.size(); ++i)
{
ON_3dPoint cpPosition = controlPoints[i];
thisCurve.SetCV(i, cpPosition.x);
}
c. add the knots
I. if you have knot_count = cv_count + degree + 1
for (int i = 1; i < knotValues.size() - 1; ++i)
thisCurve.SetKnot(i - 1, knotValues[i]);
II. If you have knot_count = cv_count + degree - 1
for (int i = 0; i < knotValues.size(); ++i)
thisCurve.SetKnot(i, knotValues[i]);
- Sample the curve
a. check if the curve is valid
if (thisCurve.IsValid())
{
b. get the parametric range of the curve
double maxU = knotValues.back();
double minU = knotValues.front();
c. interpolate
double quadrature = 10;
for (unsigned int i = 0; i < quadrature; ++i)
{
double t = ((maxU - minU) * (i) / (quadrature - 1)) + minU;
double pointsOut[3];
d. evaluate this takes (parameter of the curve, how many derivatives taken, what dimension, a double array to store values in)
bool successful = thisCurve.Evaluate(t, 0, 3, pointsOut);
if (successful)
curvePoints.push_back(ON_3dPoint(pointsOut[0], pointsOut[1], pointsOut[2]));
else
std::cout << "evaluation not successful " << std::endl;
e. clean up
delete [] pointsOut;
}
thisCurve.Destroy();