How to | Create Graphics with Spline Primitives

The Wolfram Language provides fully integrated spline graphics primitives, such as Bézier curves, B-spline curves, and B-spline surfaces. The spline primitives support a full range of user controls, such as arbitrary degree and a rational form of splines. The spline primitives provide an easy way to create complex graphics.

BezierCurve draws a composite Bézier curve that is defined by the given control points. By default, a cubic Bézier curve is used:

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

Use BSplineCurve with Graphics to create a cubic B-spline curve consisting of seven control points:

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

In general, spline curves do not go through the control points. However, they do go through the endpoints:

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

The SplineDegree option controls the underlying polynomial degrees of the spline curves. Usually, the higher the degree, the smoother the resulting curve.

Here, six different spline curves are created from the same set of control points by using Table to iterate BSplineCurve with SplineDegree changing from 1 to 6:

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

The SplineKnots option provides detailed control over the shape of a B-spline curve. Without specifying values for SplineKnots, the Wolfram Language gives the default knot sequence in such a way that the resulting curve is smooth overall and the endpoints are interpolated:

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

This is the same curve, but with the default knot values explicitly shown. The first and the last repeating knots make the curve go through the endpoints, where is the spline degree. The rest of the knots are uniformly distributed:

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

By repeating the knot value in the middle, you can decrease the smoothness of the curve:

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

When the SplineClosed option is set to True, the Wolfram Language will create a smoothly closed B-spline curve:

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

The SplineWeights option can be used to assign weights to each point. The curve will be pulled toward the points with larger weights:

In[1]:=
Click for copyable input

With no explicit setting for SplineWeights, the Wolfram Language assigns equal weights to each point:

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

Notice that the curve is pulled towards the middle point, which is given a weight of 5 with SplineWeights:

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

Mathematically, non-uniform weights create rational B-spline functions, also known as NURBS. NURBS can represent shapes that regular B-splines cannot. For instance, use BSplineCurve to create an exact circle by setting SplineWeights to the values in and SplineKnots to the values in :

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

3D spline curves can be created by using 3D points:

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

By wrapping curves with Tube, you can create tubed spline curves in 3D. Here the tube radii are 0.2:

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

A tube with various radii can be created by associating a list of radii with the control points:

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

BSplineSurface creates a tensor product B-spline surface defined by a matrix of 3D points:

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

All the options for BSplineCurve work in the same way. However, for surfaces, you can specify them in each parametric direction separately. For example, the following SplineDegree setting creates a B-spline surface with degree 1 in one direction, and degree 3 in another:

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

Like the B-spline curves, a rational surface, or NURBS surface, can be created by using SplineWeights. Many computer-aided design applications use NURBS to represent industrial surfaces. The following example generates a right-angle cylindrical tube:

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