How to | Work with Spline Functions
Mathematica's powerful spline functionality includes both numeric and symbolic support. Built-in basis polynomials and efficient spline construction provide a way to research the properties of splines as well as to perform various mathematical tasks using splines.
Mathematica provides two spline bases,
BSplineBasis and
BernsteinBasis. Like other special functions, they can be evaluated with numerical values:
| Out[1]= |  |
| Out[84]= |  |
With
Plot, you can visualize the basis functions:
| Out[3]= |  |
The basis functions can be expanded by
PiecewiseExpand to see their symbolic representation:
| Out[42]= |  |
BSplineBasis supports detailed control over the basis functions. For instance, the following plot illustrates a family of uniform quadratic B-spline basis functions by varying the second argument from

to any positive integer:
| Out[4]= |  |
A nonuniform B-spline basis can be represented by specifying a nondecreasing real sequence, called the
knots. A knot sequence defines a set of B-splines. An individual basis can be specified by the second argument ranging from

to

, where

is the length of the knot sequence and

is the degree of the B-spline:
| Out[6]= |  |
The basis functions for higher dimensions can be generated by tensor products. This shows a uniform bicubic B-spline basis function:
| Out[7]= |  |
B-spline manifolds, such as curves and surfaces, can be represented as a sum of products between B-spline basis functions and points in a range space. For example, a typical B-spline curve in 2D can be represented using
Dot:
The curve can be illustrated by using
ParametricPlot:
| Out[52]= |  |
BSplineFunction provides a convenient and efficient way to represent the B-spline curve:
| Out[53]= |  |
Similar to
InterpolatingFunction, the result from
BSplineFunction can be evaluated at a point on the given domain, or plotted using
ParametricPlot:
| Out[54]= |  |
| Out[56]= |  |
The derivative of a
BSplineFunction results in a
BSplineFunction of one lesser degree. The following example draws tangent vectors on top of the B-spline curve using the derivative:
| Out[57]= |  |
| Out[71]= |  |
BSplineFunction can also represent B-spline surfaces, which can be specified by an array of 3D points. It can be plotted by using
ParametricPlot3D:
| Out[73]= |  |
| Out[75]= |  |
The number of parameters can be given to
BSplineFunction as the second argument. For example, this generates a bivariate B-spline function:
| Out[82]= |  |
Since it is a function over

, we can use
Plot3D to display it:
| Out[83]= |  |