# B-spline basis functions

The equation for *k*-order B-spline with *n+1* control points
*(***P**_{0} , **P**_{1} , ... ,
**P**_{n} ) is

**P**(t) = ∑_{i=0,n}
N_{i,k}(t) **P**_{i} , t_{k-1} ≤
t ≤ t_{n+1} .

In a B-spline each control point is associated with a basis function
*N*_{i,k} which is given by the recurrence relations
(see also b-spline.js)

*N*_{i,k}(t) = N_{i,k-1}(t)
(t - t_{i })/(t_{i+k-1} - t_{i }) + N_{i+1,k-1}(t)
(t_{i+k} - t)/(t_{i+k} - t_{i+1 }) ,

N_{i,1} = {1 if t_{i} ≤ t
≤ t_{i+1} , 0 otherwise }

*N*_{i,k} is a polynomial of order *k* (degree *k-1*)
on each interval *t*_{i} < t < t_{i+1}.
*k* must be at least 2 (linear) and can be not more, than *n+1*
(the number of control points). A knot vector
*(t*_{0} , t_{1} , ... , t_{n+k }) must be specified.
Across the knots basis functions are *C*^{ k-2} continuous.

Corresponding iterations scheme for cubic (*k = 4*) basis functions
is shown in Fig.1 .
You see, that for a given *t* value only *k*
basis functions are non zero, therefore B-spline depends on *k* nearest
control points at any point *t*.
The B-spline basis functions as like as Bezier ones are nonnegative
*N*_{i,k} ≥ 0 and have "partition of unity" property

*∑*_{i=0,n} N_{i,k}(t) = 1,
t_{k-1} ≤ t ≤ t_{n+1}

therefore

*0 ≤ N*_{i,k} ≤ 1.

As since *N*_{i,k} = 0 for *t ≤ t*_{i} or
*t ≥ t*_{i+k} therefore a control point
**P**_{i} influences the curve only for
*t*_{i} < t < t_{i+k }.

## Knot vectors

The shapes of the *N*_{i,k} basis functions are determined entirely
by the *relative* spacing between the knots *(t*_{0} , t_{1} ,
... , t_{n+k }). Scaling or translating the
knot vector has no effect on shapes of basis functions and B-spline.
Knot vectors are generally: uniform, open uniform and non-uniform.

*Uniform knot vectors* are the vectors for which
*t*_{i+1} - t_{i} = const,
e.g. *[0,1,2,3,4,5]*.

*Open Uniform knot vectors* are uniform knot vectors which have
k-equal knot values at each end:

* t*_{i} = t_{0} , i < k

t_{i+1} - t_{i} = const , k-1 ≤ i
< n+1

t_{i} = t_{k+n} , i ≥ n+1

e.g. *[0,0,0,1,2,3,4,4,4] (k=3, n=5)*.

*Non-uniform knot vectors*. This is the general case, the only
constraint is the standard *t*_{i} ≤ t_{i+1 }.
## The main properties of B-splines

- composed of
*(n-k+2)* Bezier curves of *k*-order joined
*C*^{ k-2} continuously at knot values
*(t*_{0} , t_{1} , ... , t_{n+k })
- each point affected by
*k* control points
- each control point affected
*k* segments
- inside convex hull
- affine invariance
- uniform B-splines don't interpolate deBoor control points
*(***P**_{0} , **P**_{1} , ... , **P**_{n })

## Uniform B-splines

The principle thing to note about the uniform basis functions is that, for a
given order *k*, they are simply shifted copies of
one another (because all the knots are equispaced). You can see below, that
increasing the order *k* increases smoothness of a curve and tends
to move the curve farther from its control polygon.
## Linear B-spline (n = 3, k = 2)

In the right window you see basis polynomials.
Move a knot to see how it influences on spline shape and basis functions.
B-spline curve is composed of *(n-k+2)* segments painted in different
colors. Corresponding *t* intervals (in the right window) are painted in
the same colors.

*Interactive B-spline* Use finger or mouse to move a nearest
control point (a small blue square in
the left window) or knot (a small black square in the right window).
## Quadratic B-spline (n = 3, k = 3)

## Cubic B-spline (n = 3, k = 4)

## Closed curves (n = 5, k = 4)

To make a *C*^{ k-2} continuous closed loop you need only, that
the last *k - 1* control points repeat the first *k - 1* ones, i.e.
*[***P**_{0 }, **P**_{1 }, **P**_{2 },
**P**_{0 }, **P**_{1 }, **P**_{2 }]
for *n = 5, k = 4*
(in this example the last 3 points are displaced a bit to make them visible).

Contents
Previous: Building cubic B-spline
Next: Nonuniform B-splines

*updated* 8 August 2001