B-splines

About three month ago I published my post about Bézier curves and mentioned a follow up post about B-splines. Here it is 😉
I finished the course on Geometric Modelling and Animation in university so I thought it’s time now. Maybe there will be also a post on surfaces.

The blog post contains:

  • An explanation of B-splines
  • How to draw B-splines with different techniques
    • Normal way
    • De Boor Algorithm
  • Animations using Julia

What are B-splines?

The idea of splines in general is to combine several curves together to obtain one single curve. The curve itself should have some nice properties like continuity and it shouldn’t behave in a strange way like making weird curves as a polynomial function of degree 15 might do. Another important point is local control which means if we move one control point a little bit we don’t want to change the whole curve but only the small area around the point. For Bézier curves for example the whole curve can be changed even though the curve is changed mostly around the point that moved.

Additionally having a convex hull property is quite useful for collision detection as checking directly against the curve is quite complex which means it takes time whereas checking whether an object is inside a convex hull is easy. Later the tests can be refined if it at least has the possibility of being part of a collision with the actual curve.

In comparison to Bézier curves we gain local control, a better convex hull property and we can control the degree of the curve by combining curves together. Compared to Bézier splines we don’t have to worry about A-frames anymore which was the last part of the previous post.

Let’s have a look at a specific example:

Bezier spline vs B-spline

I have drawn this using my Bézier curve code of the last post and simple \(C^1\) continuity but for \(C^2\) this would be harder. In this example you can see the normal bezier points \(b_i\) and the so called de Boor points \(d_i\) which given the knot vector which I roughly explained last time (and the continuity) perfectly define the curve and the inner points \(b_2,b_4, b_6\) are defined implicitly by this.

I’ll come back to the Knot vector later which defines the continuity and whether it is interpolating or approximating the point. For the comparison to Bézier splines it should be end point interpolating and approximating everywhere else which means that the curve touches \(d_0\) and \(d_{end}\) but not the ones in between.

I think we need a bit more definitions for the next steps:

We have \(m+1\) de Boor points, \(d_0,\dots,d_m\) which means in the example above \(m=5\)
and degree \(n\) and the Knot Vector \(\mathbf{T} = (u_0, \dots, u_{n+m+1})\)

The spline is defined by:

\[
s(t) = \sum_{i=0}^{m} \mathbf{d}_iN_i^n(t)\]

where \(N_i^n(t)\) are the B-spline basis functions which are defined by:

\[
N_i^0(t) = \begin{cases}
1 & \text{if } u_i \leq t

\[
N_i^r(t) = \frac{t-u_i}{u_{i+r}-u_i}N_i^{r-1}(t) +
\frac{u_{i+1+r}-t}{u_{i+1+r}-u_{i+1}} N_{i+1}^{r-1}(t) \quad 1…