5

I'm using gluNurbsCurve to draw some curves with some control points. I've got the basic setup as described in the red book working correctly and I'm trying to expand on it.
This sample looks like this:

float knots[8] = {0,0,0,0,1,1,1,1};
float pnts[4][3] = { {...},{...},{...},{...} };
GLUnurbsObj *m = gluNewNurbsRenderer();
gluBeginCurve(n);
gluNurbsCurve(n, 8, knots, 3, pnts, 4, GL_MAP1_VERTEX_3)
gluEndCurve(n);

One thing I was wondering about is the meaning of the knots data. How does it affect the result? What other options can I experiment there?
For some reason I could not find any tutorial which properly explains this.

shoosh
  • 76,898
  • 55
  • 205
  • 325

2 Answers2

6

Actually there are ample sites online that explain the knot vector. It's not a GL specific thing but an inherent property of NURBS. So entering "NURBS knot vector" in google is gonna get you detailed explanations.

I'm just gonna say that usually the knot vector has a length of knot_vector_length = number_of_points + degree_of_curve + 1 and the only thing that matters is the ratio and not the absolute values. So {0,1,2,3} is the same as {0,2,4,6}

in my opinion the most important knot vectors are these:

1) {0,1,2,3,4,5,6,...}

which will allow you to easily extend the curve with curvature continuity if you repeat the last (or first) degree_of_curve-1 points but this means that that the curve doesn't actually run through its start and end points so you must repeat the last (or first) degree_of_curve-1 points to create a closed curve that is continuous.

The other important form is

2) {0,0,0,1,2,3,...,n,n,n}

whereas the 0 at the beginning and the n at the end repeat degree_of_curve + 1 times. This is also the form that you used. This will give you a NURBS curve that begins at the first point and ends at the last point you specified. But it only gives positional continuity. So if you make a closed curve with this then you are highly likely to get a tangential discontinuity.

Btw. if you only have degree_of_curve + 1 points and use the second form then you only have 0s and 1s. The resulting spline will be identical to a Bézier curve.

This is really hard to explain without images or the mathematical background (Bernstein polynomials)

PeterT
  • 7,981
  • 1
  • 26
  • 34
0
A knot vector is the curve parameter at which the continuity changes. Try to 

understand how "Bezier" curves are written. We get to create a curve whose degree is num_control_points - 1. So for a Bezier curve with 4 control points. We'd get a curve with degree 3 (order = 4). So anywhere on this curve. The continuity will be C2, meaning there is curvature continuity. A knot vector for this curve will be (0, 0, 0, 0, 1, 1, 1, 1). This is from the code snippet you gave above. You have provided the knot vector and the control points of the curve.

So, one can tell that at parameter 0. There is C0 continuity. The same at parameter 1. The more knot values for a paramter. It means that the continuity at that parameter is reducing. Hope you understand what I'm telling. Since the degree of the curve is 3. The continuity drops from ( C3 -> C2 -> C1 -> C0 ). That's what the ( 0 -> 0 -> 0 -> 0) stands for.

I am still researching(studying :P ) how in an uniform knot vector case, the curve begins somewhere midway. As for now, assume a case where the knot vector is (0, 1, 2, 3..7). This tells that between paramters 0 - 1. There is one curve. Between 1 - 2, there is another. So basically we broke the entire curve into 7 pieces(of course, the degree is dependent on you). If I take this as a curve with degree 3. It means I have 7 different curves each with degree 3.

Hope you followed what I said. As step 1. try to understand the meaning of knot vectors, step 2 will be how these are used in the Cox De-Boor recursive equation(which gets a tad complex). Finally you'll see what weights mean. That's the reason for the "R" in the acronym NURBS(Non Uniform Rationalized B splines). The snippet you gave was for a Uniform B spline curve. So basically, NURBS is just a conglomeration of any curve possible. :)