This is documentation for Mathematica 3, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.2)
 Documentation / Mathematica / Add-ons / Standard Packages / Graphics  /

Graphics`Spline`


A spline graphics primitive.

This package takes the functions from NumericalMath`SplineFit` and adapts them to a graphics primitive. Currently, three types of splines are supported: Cubic, Bezier, and CompositeBezier. See the documentation for the NumericalMath`SplineFit` package for more information about the various types of splines.

  • This loads the package.
  • In[1]:= <<Graphics`Spline`

  • Here is a list of points.
  • In[2]:= pts =
    {{0, 0}, {1, 2}, {-1, 3}, {0, 1}, {3, 0}};

  • This is a graph of the cubic Spline primitive combined with other primitives. Here a line of a different color connects the points making up the spline.
  • In[3]:= Show[
    Graphics[{Hue[0], Line[pts], GrayLevel[0],
    Spline[pts, Cubic]}],
    PlotRange -> All]


  • Compare the cubic spline of the previous example to a Bezier spline.
  • In[4]:= Show[
    Graphics[{Hue[0], Line[pts], GrayLevel[0],
    Spline[pts, Bezier]}],
    PlotRange -> All]



    Options for Spline.

    The spline graphics primitive has an option allowing the control points to be shown. By setting the SplineDots option to a style primitive (or list of style primitives), you can control the characteristics of these points. Setting it to None will suppress the display of the points, while setting it to Automatic will place red dots at each point.

  • Here is a spline with the control points shown.
  • In[5]:= Show[Graphics[Spline[pts, CompositeBezier,
    SplineDots -> Automatic]]]


    The rendering of the splines uses an adaptive algorithm, similar to that of the Plot function. The initial number of samples taken along the spline is determined by SplinePoints. If the bend between two adjacent segments is greater than MaxBend, additional samples are taken. This process continues up to at most a resolution determined by SplineDivision. If SplineDivision is None, then adaptive methods will not be used; samples will only be taken where determined by SplinePoints. This will be useful on occasion, as the adaptive method is relatively slow.
    When rendering a spline in the usual fashion, a Line graphics primitive is generated behind the scenes. It may be useful to incorporate the points of this primitive into other Line and Polygon primitives. In particular, you can create a polygon with a spline along one or more sides.

  • This represents a Bezier curve.
  • In[6]:= bcurve =
    Spline[
    {{1,0},{1.5,0},{1.5,0.5},
    {2,1.5},{0.7,1.6},{0,1.5},{0,1}},
    Bezier];

  • Here is a polygon with a spline incorporated into one side.
  • In[7]:= Show[
    Graphics[
    Polygon[
    {{0,1},{0,0},{1,0},bcurve}]
    ]]


    The default method of rendering splines is the adaptive method described above; internally, this generates a MathematicaLine primitive. In some special cases, however, it is advantageous for Mathematica to use special PostScript operators that are not part of the Mathematica graphics primitives. For example, a Bezier spline with four points corresponds to the PostScript curveto operator.
    Advanced users can force Mathematica to generate special PostScript code for other kinds of splines by modifying the package function RenderSpline. Interested users can see the package itself for an example of this.