# NewGamePhysics.Mathematics.CubicSpline Class Reference

N-dimensional cubic spline interpolator. More...

List of all members.

## Public Member Functions
| CubicSpline ()
| Creates an instance of the cubic spline class with one dimension.
| CubicSpline (int dimensions)
| Creates an instance of the cubic spline class with the specified number of dimensions.
void | Clear ()
| Clears the data array of the spline.
bool | AddDataPoint (double x, double[] y)
| Adds a data point to the spline. If the data point is added, the coefficients are recalculated the next time Interpolate() is called.
double[] | Interpolate (double x)
| Interpolate spline at position X. May recalculate coefficients if they need to be updated (i.e. after AddDataPoint).
## Properties
double | Dimensions`[get]`
| Gets the number of dimensions of the spline.
double | Count`[get]`
| Gets the number of points in the spline.
bool | CanInterpolate`[get]`
| Gets a flag indicating wether sufficient points have been added so that interpolation can occur.

## Detailed Description

N-dimensional cubic spline interpolator.

Definition at line 15 of file CubicSpline.cs.

## Constructor & Destructor Documentation

NewGamePhysics.Mathematics.CubicSpline.CubicSpline | ( |  | ) |

Creates an instance of the cubic spline class with one dimension.

Definition at line 65 of file CubicSpline.cs.

    00066             : this(1)
    00067         {
    00068         }

NewGamePhysics.Mathematics.CubicSpline.CubicSpline | ( | int | dimensions | ) |

Creates an instance of the cubic spline class with the specified number of dimensions.

Definition at line 74 of file CubicSpline.cs.

    00075         {
    00076             if (dimensions < 1)
    00077             {
    00078                 throw new ArgumentOutOfRangeException(
    00079                     "dimensions",
    00080                     "The number of dimensions must be 1 or more");
    00081             }
    00082
    00083             this.dimensions = dimensions;
    00084             this.data = new SortedList<double, double[]>();
    00085             this.bCoeff = new double[dimensions][];
    00086             this.cCoeff = new double[dimensions][];
    00087             this.dCoeff = new double[dimensions][];
    00088             this.needUpdate = false;
    00089         }

## Member Function Documentation

bool NewGamePhysics.Mathematics.CubicSpline.AddDataPoint | ( | double | x,
|  | double[] | y |
| ) |  |  |

Adds a data point to the spline. If the data point is added, the coefficients are recalculated the next time Interpolate() is called.

Parameters:

  | x | X coordinate of the spline. Must be unique (i.e. not added before).
  | y | Y coordinates of the spline. The number of values in the array must match the number of dimensions if the spline.

Returns:
  True if the point was added, false otherwise.

Definition at line 155 of file CubicSpline.cs.

    00156         {
    00157             if (y.Length != this.dimensions)
    00158             {
    00159                 throw new ArgumentOutOfRangeException(
    00160                     "y",
    00161                     "The array must contain " + this.dimensions + " values.");
    00162             }
    00163
    00164             if (this.data.ContainsKey(x))
    00165             {
    00166                 return false;
    00167             }
    00168             else
    00169             {
    00170                 this.data.Add(x, y);
    00171                 this.needUpdate = true;
    00172                 return true;
    00173             }
    00174         }

void NewGamePhysics.Mathematics.CubicSpline.Clear | ( |  | ) |

Clears the data array of the spline.

Definition at line 128 of file CubicSpline.cs.

    00129         {
    00130             this.data.Clear();
    00131             this.xData = null;
    00132             this.xIntervals = null;
    00133             this.yData = null;
    00134             for (int i = 0; i < this.dimensions; i++)
    00135             {
    00136                 this.bCoeff[i] = null;
    00137                 this.cCoeff[i] = null;
    00138                 this.dCoeff[i] = null;
    00139             }
    00140
    00141             this.needUpdate = false;
    00142         }

double [] NewGamePhysics.Mathematics.CubicSpline.Interpolate | ( | double | x | ) |

Interpolate spline at position X. May recalculate coefficients if they need to be updated (i.e. after AddDataPoint).

Parameters:

  | x | Position X.

Returns:
  Interpolated Y.

Definition at line 182 of file CubicSpline.cs.

    00183         {
    00184             if (!this.CanInterpolate)
    00185             {
    00186                 throw new InvalidOperationException(
    00187                     "Insufficient number of points. Add at least 4 points before calling Interpolate.");
    00188             }
    00189
    00190             if (this.needUpdate)
    00191             {
    00192                 this.CalculateCoefficients();
    00193             }
    00194
    00195             int index = BinaryIndexSearch(this.xData, x);
    00196             double dx = x - this.xData[index];
    00197             double[] y = new double[this.dimensions];
    00198             for (int i = 0; i < this.dimensions; i++)
    00199             {
    00200                 y[i] = ((this.dCoeff[i][index] * dx + this.cCoeff[i][index]) * dx + this.bCoeff[i][index]) * dx + this.yData[i][index];
    00201             }
    00202
    00203             return y;
    00204         }

## Property Documentation

bool NewGamePhysics.Mathematics.CubicSpline.CanInterpolate`[get]`

Gets a flag indicating wether sufficient points have been added so that interpolation can occur.

Definition at line 118 of file CubicSpline.cs.

double NewGamePhysics.Mathematics.CubicSpline.Count`[get]`

Gets the number of points in the spline.

Definition at line 106 of file CubicSpline.cs.

double NewGamePhysics.Mathematics.CubicSpline.Dimensions`[get]`

Gets the number of dimensions of the spline.

Definition at line 95 of file CubicSpline.cs.

The documentation for this class was generated from the following file:

- C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/NewGamePhysics/Mathematics/CubicSpline.cs