How to | Create Graphics with Spline Primitives
Mathematica 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:
| Out[85]= |  |
Use
BSplineCurve with
Graphics to create a cubic B-spline curve consisting of seven control points:
| Out[93]= |  |
In general, spline curves do not go through the control points. However, they do go through the endpoints:
| Out[90]= |  |
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:
| Out[88]= |  |
The
SplineKnots option provides detailed control over the shape of a B-spline curve. Without specifying values for
SplineKnots,
Mathematica gives the default knot sequence in such a way that the resulting curve is smooth overall and the endpoints are interpolated:
| Out[2]= |  |
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:
| Out[133]= |  |
By repeating the knot value

in the middle, you can decrease the smoothness of the curve:
| Out[134]= |  |
When the
SplineClosed option is set to
True,
Mathematica will create a smoothly closed B-spline curve:
| Out[3]= |  |
| Out[4]= |  |
The
SplineWeights option can be used to assign weights to each point. The curve will be pulled toward the points with larger weights:
With no explicit setting for
SplineWeights,
Mathematica assigns equal weights to each point:
| Out[7]= |  |
Notice that the curve is pulled towards the middle point, which is given a weight of 5 with
SplineWeights:
| Out[8]= |  |
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

:
| Out[108]= |  |
3D spline curves can be created by using 3D points:
| Out[9]= |  |
| Out[10]= |  |
By wrapping curves with
Tube, you can create tubed spline curves in 3D. Here the tube radii are 0.2:
| Out[11]= |  |
| Out[12]= |  |
A tube with various radii can be created by associating a list of radii with the control points:
| Out[15]= |  |
BSplineSurface creates a tensor product B-spline surface defined by a matrix of 3D points:
| Out[160]= |  |
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:
| Out[162]= |  |
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:
| Out[8]= |  |