Drawing NURBS Curves?

7k views Asked by At

for the past week I've been facing this problem. For my current project I need to draw NURBS curves, the project already uses OpenNURBS, but I wasn't able to figure out how to use it.

My question is, how can I get the curve points from a few control points ?

I've done quite a bit of searching, and I saw this website: http://www.nar-associates.com/nurbs/c_code.html

I can use the code, but I don't understand how to extend/simplify it to use N amount of control points.

(Also, I'm using C++ so I converted the code from the page to the said language, answers specific to C++ would be better, but I don't have any problems converting between languages.)

3

There are 3 answers

3
Tutankhamen On

try this library:

http://libnurbs.sourceforge.net/

Non-Uniform Rational B-Splines (NURBS) curves and surface are very general mathematical surfaces widely used for representing complex three dimensional shapes in computer graphics.

The goal of libnurbs is to provide a clean, robust and powerful library with the ability to define, manipulate, and analyze NURBS curves and surfaces. We will be building off of the foundation provided by the openNURBS library, implementing functionality missing from that library and making changes as needed. The goal of the openNURBS effort is increased interoperabilty between various CAD systems, so they have no incentive to develop or release a more full-featured library (that's Rhino, their commercial platform) - hence the need for this project.

0
splineducks On

You can draw NURBS curve online with this free tool . This is a webGL based application and works best in Chrome browser. Here you can draw curves with N number of control points and see the value of a point on the curve corresponding to a u parameter.

0
brettmichaelgreen On

Here's how I do it

  1. 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]);
  1. 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();