How to | Work with Spline Functions

The Wolfram Language'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.

The Wolfram Language provides two spline bases, BSplineBasis and BernsteinBasis. Like other special functions, they can be evaluated with numerical values:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

With Plot, you can visualize the basis functions:

In[3]:=
Click for copyable input
Out[3]=

The basis functions can be expanded by PiecewiseExpand to see their symbolic representation:

In[4]:=
Click for copyable input
Out[4]=

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:

In[5]:=
Click for copyable input
Out[5]=

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:

In[6]:=
Click for copyable input
Out[6]=
    

The basis functions for higher dimensions can be generated by tensor products. This shows a uniform bicubic B-spline basis function:

In[1]:=
Click for copyable input
Out[1]=
    

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:

In[1]:=
Click for copyable input

The curve can be illustrated by using ParametricPlot:

In[2]:=
Click for copyable input
Out[2]=

BSplineFunction provides a convenient and efficient way to represent the B-spline curve:

In[3]:=
Click for copyable input
Out[3]=

Similar to InterpolatingFunction, the result from BSplineFunction can be evaluated at a point on the given domain, or plotted using ParametricPlot:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=

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:

In[6]:=
Click for copyable input
Out[6]=
In[7]:=
Click for copyable input
Out[7]=
    

BSplineFunction can also represent B-spline surfaces, which can be specified by an array of 3D points. It can be plotted by using ParametricPlot3D:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

The number of parameters can be given to BSplineFunction as the second argument. For example, this generates a bivariate B-spline function:

In[3]:=
Click for copyable input
Out[3]=

Since it is a function over , we can use Plot3D to display it:

In[4]:=
Click for copyable input
Out[4]=