This is Words and Buttons Online — a collection of interactive #tutorials, #demos, and #quizzes about #mathematics, #algorithms and #programming.

NURBS is just an acronym

Previously we only talked about Bézier-like spline interpolation and a special case of local quadratic splines, which is essentially an interpolation as well.

Interpolation is simple. You set some control points and you expect a curve to run through all of them. It is intuitive. But it is also limiting. What if you want to control a curve between the control points? What if you want some points to denote a sharp angle and some not? What if you want some points to attract a curve more than the other?

NURBS is one way to answer these questions. Basis spline that is non-uniform and rational.

NURBS = Non
        Uniform
        Rational
        Basis
        Spline

Let's go through these concept one in a time.

...BS is for basis spline

The idea here is: for each parameter t we can get a pair of (x, y), that will form a nice continuous curve, by mixing our control points in different proportions determined by some function of t. For the basis spline, these proportions are determined by the basis polynomials of a certain degree.

Just like with the polynomial interpolation, you need a certain amount of points to set a polynomial. 2 points for linear, 3 for quadratic, 4 for cubic, etc. This means that if we have 5 control points, and we want to turn them into a piecewise polynomial function, we should expect a 4-piece piecewise linear, 3-piece piecewise quadratic, 2-piece piecewise cubic, or a single polynomial of a degree 4.

Here is the example or NURBS-curve built by de Boor's algorithm. You can select the basis polynomial degree, and you can move control points around as well. For now, it consists of parametrically equal pieces, each one having its own color. The higher the degree — the shorter the curve you get. It's ok, you get fewer basis polynomials — ergo fewer pieces, and we keep them equal for now.

Degree of the basis spline:

The very basic input for NURBS is a set of control points and a basis polynomial degree. But that's not all.

NU... is for non-uniform

Having equal parametric pieces may not always be the best. That's why we need our spline to be non-uniform. Being able to select how long we want our pieces to be, and where to start, and where to end, — it all adds another level of control.

Here is the same spline, but beneath it, there is a rainbow stripe. Every color represents a parametric piece. You can drag them left and right to change their lengths.


The input for a NURBS therefore also consists of a knot vector. Every knot is a number in parametric space. As you can see, there are usually more knots than the control points because the higher the degree of basis polynomials, the more knots affect every single piece. Even invisible pieces of the stripe affect the visible pieces of the spline.

...R... is for rational

This may be tricky if you are not familiar with the concept of homogeneous coordinates. Long story short, there is a less popular way to denote points on a plane. Usually, we do it like this:

P = (x, y)

But we may as well add a third coordinate keeping a correspondence between the two by dividing the first two by the third. That's where the rational spline comes from.

P = (xh, yh, wh)
x = xh / wh
y = yh / wh

Not getting into the rationale for that in the general case, for us this affects the polynomial weighting scheme in a rather pragmatic way. The points with greater w “attract” the curve more. This is yet again another way to control our output.

These are the weights of points. You can drag them up and down.

Of course, you don't see this, but under the hood, the points' x and y coordinates are aligned with the w to keep the ratio. This means if you don't want to get deep into all this homogeneous stuff, that for NURBS every point has its weight put into all the three coordinates.

wh: (x, y) = (xhwh, yhwh, wh).

This completes the input for NURBS.

Conclusion

To build a NURBS curve you need:

But why bother? Why do we need all this control? What's wrong with simple Bézier splines?

For one, you can't do this with Bézier:

This is a real circle, not a model. The NURBS recipe is:

degree = 2;

xs = [1,  √2/2,  0, -√2/2, -1, -√2/2,  0,  √2/2,  1]
ys = [0,  √2/2,  1,  √2/2,  0, -√2/2, -1, -√2/2,  0]
ws = [1,  √2/2,  1,  √2/2,  1,  √2/2,  1,  √2/2,  1]

knots = [0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4]
	

Ok, I also had to scale and translate it to make it bigger and fit a plot canvas nicer. But that's irrelevant. What is important, with NURBS you can do analytical curves: lines, circles, conics, etc. And, of course, you can do Bézier curves as well. You don't need special kinds of objects for all that, they all play by the same rules, they all are representable with knots and points.

That's why NURBS are so popular in CAD systems. Not because they are complicated, but because they make computational geometry simpler.

P. S.

All the source code for this site is available on GitHub. This particular page is: https://github.com/.../pages/nurbs_is_just_an_acronym.html. If you want to play with NURBS more extensively than this page allows you, please do.