Next: spline Invocation, Previous: spline Examples, Up: spline

`spline`

The preceding section explains how `spline`

can be employed to
interpolate a function y of a scalar variable t, in the
case when y is a scalar. In this section we explain how to
perform more sophisticated interpolations. This includes
multidimensional interpolations, and interpolations that are splinings
of curves, rather than of functions.

`spline`

can handle the case when y is a vector of
arbitrary specified dimensionality. The dimension can be specified with
the ‘`-d`’ option. For example, an input file could contain the
multidimensional dataset

0.0 0.0 1.0 1.0 1.0 0.0 2.0 0.0 1.0

which are the coordinates (t,y) of the data points (0,0,1), (1,1,0), and (2,0,1). You would construct a spline (the graph of an interpolating function) passing through the points in this dataset by doing

spline -d 2 input_file > output_file

The option ‘`-d 2`’ is used because in this example, the dependent
variable y is a two-dimensional vector. Each of the components
of y will be interpolated independently, and the output file will
contain points that lie along the graph of the resulting interpolating
function.

When doing multidimensional splining, you may use any of the options
that apply in the default one-dimensional case. For example, the
‘`-f`’ option will yield real-time cubic Bessel interpolation. As in the one-dimensional case, if the ‘`-f`’ option is used then the
‘`-t`’ option must be used as well, to specify an interpolation
interval (a range of t values). The ‘`-p`’ option
will yield a periodic spline, i.e., the graph of a periodic
vector-valued function. For this, the first and last dataset
y values must be the same.

`spline`

can also be used to draw a curve through arbitrarily
chosen points in the plane, or in general through arbitrarily chosen
points in d-dimensional space. This is not the same as splining,
at least as the term is conventionally defined. The reason is that
`splining' refers to construction of a function, rather than the
construction of a curve that may or may not be the graph of a function.
Not every curve is the graph of a function.

The following example shows how you may `spline a curve'. The command

echo 0 0 1 0 1 1 0 1 | spline -d 2 -a -s | graph -T X

will construct a curve in the plane through the four points (0,0),
(1,0), (1,1), and (0,1), and graph it on an X Window System display.
The ‘`-d 2`’ option specifies that the dependent variable y is
two-dimensional. The ‘`-a`’ option specifies that t values are missing from the input, and should be automatically
generated. By default, the first t value is 0, the
second is 1, etc. The ‘`-s`’ option specifies that the
t values should be stripped from the output.

The same technique may be used to spline a closed curve. For example, doing

echo 0 0 1 0 0 1 0 0 | spline -d 2 -a -s -p | graph -T X

will construct and graph a closed, lozenge-shaped curve through the
three points (0,0), (1,0), and (0,1). The construction of a closed
curve is guaranteed by the ‘`-p`’ (i.e., ‘`--periodic`’) option,
and by the repetition of the initial point (0,0) at the end of the
sequence.

When splining a curve, whether open or closed, you may wish to
substitute the ‘`-A`’ option for the ‘`-a`’ option. Like the
‘`-a`’ option, the ‘`-A`’ option specifies that t values are missing from the input and should be automatically
generated. However, the increment from one t value to the
next will be the distance between the corresponding values of y. This scheme for generating t values, when
constructing a curve through a sequence of data points, is the scheme
that is used in the well known FITPACK subroutine library. It is probably the best approach when the distances between successive
points fluctuate considerably.

A curve through a sequence of points in the plane, whether open or closed, may cross itself. Some interesting visual effects can be obtained by adding negative tension to such a curve. For example, doing

echo 0 0 1 0 1 1 0 0 | spline -d 2 -a -s -p -T -14 -n 500 | graph -T X

will construct a closed curve through the three points (0,0), (1,0),
and (0,1), which is wound into curlicues. The ‘`-n 500`’ option is
included because there are so many windings. It specifies that 501
points should be generated, which is enough to draw a smooth curve.