org.faceless.graph.math

## Class Spline

• ```public class Spline
extends FunctionCurve```

Create a Spline Curve, or more accurately a sequence of spline curves which can be used to interpolate or approximate, or just plain "Smooth" a `DataCurve`.

Currently this class provides two pre-defined spline curves which can be mapped to a collection of data points.

A Catmull-Rom spline is a spline curve which passes through every point on the `DataCurve`, guaranteed.
A B-Spline is a spline curve which approximates the data points it's based on. A B-Spline may not pass through any of the points supplied, but will tend to lessen the influence of "spikes" in the data. B-Splines conventionally use the first and last points as control points only. This class generates useful values for the first and last points on the `DataCurve` by repeating the first and last values in the data set.

The curves are defined by the basis matrix for the spline. If the basis matrix has less rows than the number of points in the datacurve, several curves are "patched" together, using the n points of the datacurve starting at point 0, then point 1, then point 2 and so on.

If you haven't understood a word of this, you failed calculus at school, but you still still want your curves to be nice and smooth, just use a Catmull-Rom spline like this:

```   DataCurve data = new DataCurve();
data.add(x,y);                       // Add data to the curve
.
.
Curve smooth = new Spline(Spline.CATMULLROM, data);
```
See Also:
`Matrix`, `DataCurve`
• ### Field Summary

Fields
Modifier and Type Field and Description
`static Matrix` `BSPLINE`
Defines the basis matrix for a B-spline
`static Matrix` `CATMULLROM`
Defines the basis matrix for a Catmull-Rom spline
• ### Constructor Summary

Constructors
Constructor and Description
```Spline(Matrix matrix, DataCurve d)```
Return a new Spline curve of the specified type fitted to the supplied `DataCurve`.
```Spline(Matrix matrix, double[] x, double[] y)```
Return a new Spline curve of the specified type fitted to the array of X and Y values supplied.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `get(double x)`
Return the value of the spline at the specified X value.
`double` `getMax()`
Return the maximum value that is defined for this curve.
`double` `getMin()`
Return the minimum value that is defined for this curve.
`boolean` `point(double x)`
If a marker is to be placed at this point on the curve then return true, otherwise return false.
`double[]` `steps()`
Return the points on the curve that it should be sampled at to get an accurate picture of it.
• ### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Field Detail

• #### CATMULLROM

`public static final Matrix CATMULLROM`
Defines the basis matrix for a Catmull-Rom spline
• #### BSPLINE

`public static final Matrix BSPLINE`
Defines the basis matrix for a B-spline
• ### Constructor Detail

• #### Spline

```public Spline(Matrix matrix,
DataCurve d)```
Return a new Spline curve of the specified type fitted to the supplied `DataCurve`.
Parameters:
`matrix` - The basis matrix for the curve. May be `CATMULLROM`, `BSPLINE` or a user-defined 4x4 matrix.
`d` - the data-curve to fit to.
• #### Spline

```public Spline(Matrix matrix,
double[] x,
double[] y)```
Return a new Spline curve of the specified type fitted to the array of X and Y values supplied. Note that although a Spline may loop back on itself (i.e. for any X position there may be more than one Y value) this class does not account for it (as it's meaning is to smooth curves, not provide a fully fledged spline interpolator). The results are undefined if the data passed in loops back upon itself.
Parameters:
`matrix` - The basis matrix for the curve. May be `CATMULLROM`, `BSPLINE` or a user-defined matrix.
`x` - the X values to fit the curve to
`y` - the Y values to fit the curve to
• ### Method Detail

• #### get

`public double get(double x)`
Return the value of the spline at the specified X value. Note that unlike other spline libraries you may encounter, the value supplied is not the position along the length of the curve, but the position on the X axis. Remember this class is intended only for use with Line Graphs, not for general spline interpolation.
Specified by:
`get` in class `Curve`
• #### getMin

`public double getMin()`
Description copied from class: `Curve`
Return the minimum value that is defined for this curve. For curves with no minimum (like most mathematical functions), this should return `Double.POSITIVE_INFINITY` (yes, positive)
Overrides:
`getMin` in class `FunctionCurve`
• #### getMax

`public double getMax()`
Description copied from class: `Curve`
Return the maximum value that is defined for this curve. For curves with no maximum (like most mathematical functions), this should return `Double.NEGATIVE_INFINITY` (yes, negative)
Overrides:
`getMax` in class `FunctionCurve`
• #### steps

`public double[] steps()`
Description copied from class: `Curve`
Return the points on the curve that it should be sampled at to get an accurate picture of it. Subclasses of `FunctionCurve` may return an empty list if they wish, or if there are certain points that the curve must be sampled at, it can return them here.
Overrides:
`steps` in class `FunctionCurve`
• #### point

`public boolean point(double x)`
Description copied from class: `Curve`
If a marker is to be placed at this point on the curve then return true, otherwise return false. Most `FunctionCurve` will return false, but curves that have been fitted to a `DataCurve` may return any points from that `DataCurve` that are matched exactly by the fitted curve.
Overrides:
`point` in class `FunctionCurve`

Copyright © 2001-2017 Big Faceless Organization