# 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:

In[85]:= |

Out[85]= |

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

In[93]:= |

Out[93]= |

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

In[89]:= |

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:

In[87]:= |

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:

In[1]:= |

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:

In[133]:= |

Out[133]= |

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

In[134]:= |

Out[134]= |

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

In[2]:= |

In[3]:= |

Out[3]= |

In[4]:= |

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:

In[6]:= |

With no explicit setting for SplineWeights, *Mathematica* assigns equal weights to each point:

In[7]:= |

Out[7]= |

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

In[8]:= |

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 :

In[105]:= |

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

In[9]:= |

Out[9]= |

In[10]:= |

Out[10]= |

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

In[11]:= |

Out[11]= |

In[12]:= |

Out[12]= |

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

In[14]:= |

In[15]:= |

Out[15]= |

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

In[159]:= |

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:

In[162]:= |

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:

In[5]:= |

Out[8]= |