Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 50 ยท Curves and Surfaces

B-Splines and NURBS

Learn B-splines and NURBS: knot vectors, Cox-de Boor basis functions, local control, clamped curves and weights that draw exact circles, with live editors.

A single Bezier curve has two problems when shapes get long. Its degree grows with the number of control points, which makes it expensive and wobbly. And every control point influences the whole curve, so a tiny edit at one end shifts the other end too. The usual workaround, chaining many cubic pieces, forces you to keep the joints smooth by hand.

B-splines (basis splines) solve both problems at once. They give you one list of control points and one choice of a small degree, say 3, and produce a whole chain of polynomial pieces that is automatically smooth where they join. Each control point only affects a short stretch of the curve. NURBS go one step further by adding a weight to each point, and with it the ability to describe circles and other conic shapes exactly. They are the standard curve type in CAD and 3D modeling software.

Basis functions

Like a Bezier curve, a B-spline is a blend of control points:

TEXT
C(t) = sum over i of  N(i,p)(t) * Pi

The difference lies in the weights N(i,p)(t), the B-spline basis functions of degree p. A Bernstein weight is non-zero across the entire parameter range. A B-spline basis function is a small bump that is non-zero only over p + 1 consecutive pieces of the parameter axis and exactly zero elsewhere. That is the whole secret of local control: control point Pi can only pull on the part of the curve where its bump is non-zero.

The bumps are defined by a list of numbers called the knot vector, t0 <= t1 <= t2 <= ... , which marks where the polynomial pieces meet. The definition is the Cox-de Boor recursion:

TEXT
N(i,0)(t) = 1 if t(i) <= t < t(i+1), else 0

N(i,p)(t) =  (t โˆ’ t(i)) / (t(i+p) โˆ’ t(i))       * N(i,pโˆ’1)(t)
           + (t(i+p+1) โˆ’ t) / (t(i+p+1) โˆ’ t(i+1)) * N(i+1,pโˆ’1)(t)

with the convention that a term with a zero denominator is zero. In words: a degree-0 function is a box over one knot interval; each increase in degree blends two neighboring lower-degree functions with a linear ramp up and a linear ramp down, making the result smoother and wider.

JavaScript
function basis(i, p, t, knots) {
  if (p === 0) return knots[i] <= t && t < knots[i + 1] ? 1 : 0;
  let a = 0, b = 0;
  const d1 = knots[i + p] - knots[i], d2 = knots[i + p + 1] - knots[i + 1];
  if (d1 > 0) a = (t - knots[i]) / d1 * basis(i, p - 1, t, knots);
  if (d2 > 0) b = (knots[i + p + 1] - t) / d2 * basis(i + 1, p - 1, t, knots);
  return a + b;
}

For n + 1 control points and degree p you need n + p + 2 knots, and the curve is defined on the parameter range t(p) <= t < t(n+1). These basis functions have the same good properties as Bernstein polynomials: they are non-negative, sum to 1 inside the valid range (so the curve lies in the convex hull of the control points, and in fact in the hull of just the p + 1 points nearby), and they are as smooth as the knots allow. For distinct knots a degree-p B-spline is C(pโˆ’1) continuous at every knot: a cubic is C2, which is smoother than the C1 chain of Catmull-Rom or Bezier pieces.

Select the degree and the number of control points in the first demo and look at the bumps. Each color is the weight of one control point. With a cubic, every bump covers four knot intervals, and at any t at most four weights are non-zero.

B-spline basis functions

Knot vectors: uniform, clamped and repeated

The knot vector controls the shape of the curve as much as the control points do:

  • Uniform (periodic): knots are evenly spaced, 0 1 2 3 .... The curve does not reach the first and last control points; it starts and ends inside the control polygon, in the region where all p + 1 bumps overlap. Fine for closed loops (repeat the first points at the end), but awkward for open curves.
  • Clamped (open uniform): the first and last knot are repeated p + 1 times, for a cubic 0 0 0 0 1 2 3 ... k k k k. Now the curve starts exactly at P0 and ends exactly at Pn and is tangent to the first and last segments of the control polygon, just like a Bezier curve. This is the default in most tools.
  • Repeated interior knots: making a knot appear m times lowers the continuity there by m โˆ’ 1 steps. A cubic with a knot of multiplicity 3 is only C0 there: the curve touches the control point and forms a corner. With multiplicity 4 the curve breaks.

A neat fact: a clamped B-spline with exactly p + 1 control points and no interior knots (0 0 0 0 1 1 1 1 for a cubic) is a Bezier curve. B-splines contain Bezier curves as the special case, and any B-spline can be split into a chain of Bezier segments by knot insertion, which adds knots without changing the shape.

Evaluating and editing

To evaluate the curve at t, you only need the few basis functions that are non-zero there. The textbook recursion above is fine for learning; production code uses de Boor's algorithm, which is the sibling of de Casteljau's: a triangular scheme of repeated interpolations that touches only the p + 1 relevant control points.

The editor below draws a B-spline through your control polygon. Drag the points. Switch the degree: degree 1 is just the polygon, degree 2 cuts its corners, and degree 3 is smoother still. Observe how much less the curve moves when you drag a point compared with the global effect in a Bezier curve. Only the stretch near that point changes. Dots on the curve mark where the knots fall (the joints between the polynomial pieces).

B-spline editor

NURBS: weights and exact conics

Polynomial curves, Bezier and B-splines alike, cannot represent a circle exactly. A cubic Bezier approximation of a quarter circle is accurate to about 0.03%, which is fine for drawing but not for manufacturing or for geometry that must be exact. The fix is to use rational curves, the ratio of two polynomials. A NURBS (Non-Uniform Rational B-Spline) gives every control point a weight wi and divides:

TEXT
C(t) = ( sum N(i,p)(t) * wi * Pi ) / ( sum N(i,p)(t) * wi )

The name lists the ingredients: non-uniform because the knot spacing may be uneven, rational because of the division, B-spline because of the basis functions. The weights have an intuitive meaning: a larger wi pulls the curve toward Pi, and a smaller one pushes it away. All weights equal to 1 gives back an ordinary B-spline. This is also how a homogeneous coordinate works, as in the homogeneous coordinates lesson: a NURBS is an ordinary B-spline in 4D, divided by its last coordinate.

The most famous result: with degree 2, nine control points at the corners and edge midpoints of a square, and weight โˆš2/2 at the corner points of the control polygon that are not on the circle (the others 1), the curve is a mathematically perfect circle. The demo draws that NURBS in blue and an ideal circle in dashed red. Slide the weight: at 0.7071 (exactly โˆš2/2) both coincide. Other values still give smooth, circle-like curves, but pulled toward the corners (large weights) or pushed toward a diamond (small weights).

A circle from a NURBS

Because they can mix free-form shapes with exact circles, cylinders, spheres and cones, NURBS became the common language of CAD systems and data exchange formats such as STEP and IGES. Modeling software for animation, such as Blender or Rhino, offers them as curve and surface types. A NURBS surface is a grid of control points with two knot vectors, evaluated with the product of two basis functions, an idea you will meet in Bezier surfaces.

Choosing between curve types

Curve Passes through points Local control Typical use
Catmull-Rom all of them yes animation paths, strokes
Bezier (cubic) first and last per segment fonts, SVG, vector art
B-spline usually none (unless clamped ends) yes smooth design curves
NURBS usually none yes CAD, exact circles

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why do B-splines offer local control?

    A degree-p basis function is a bump covering p + 1 intervals, so a control point only influences the part of the curve where its bump is non-zero.
  2. 2. How many knots does a B-spline of degree p with n + 1 control points need?

    The count is control points plus degree plus one: (n + 1) + p + 1 = n + p + 2.
  3. 3. What does a clamped knot vector achieve?

    Repeating the end knots p + 1 times makes the curve start at P0 and end at Pn, like a Bezier curve.
  4. 4. What is the continuity of a cubic B-spline at a simple (non-repeated) interior knot?

    A degree-p spline with distinct knots is C(p-1) continuous. For a cubic that is C2.
  5. 5. What do the weights of a NURBS add compared with a B-spline?

    Dividing by the weighted basis sum makes the curve rational, which is exactly what a circle needs. All weights equal to 1 gives back an ordinary B-spline.

Summary

  • A B-spline blends control points with basis functions defined by a knot vector (Cox-de Boor recursion); each basis is a small bump, so control is local.
  • A degree-p B-spline needs n + p + 2 knots for n + 1 points and is C(p-1) at simple knots; a cubic is C2.
  • Clamped knot vectors make the curve touch the end points; repeated knots lower the continuity; Bezier curves are a special case.
  • NURBS add a weight per point and divide by the weighted basis sum, which allows exact conics such as circles.
  • Choose Catmull-Rom to pass through data, Bezier for vector art, B-splines and NURBS for smooth, locally editable design shapes.

Next: extend curves to surfaces and to self-similar shapes in Bezier Surfaces and Fractals.