## GOCSpline

GOCSpline

## Synopsis

                        GOCSpline;
    enum                GOCSplineType;
    GOCSpline*          go_cspline_init                     (double const *x,
                                                             double const *y,
                                                             int n,
                                                             unsigned  limits,
                                                             double c0,
                                                             double cn);
    void                go_cspline_destroy                  (GOCSpline *sp);
    double              go_cspline_get_value                (GOCSpline const *sp,
                                                             double x);
    double              go_cspline_get_deriv                (GOCSpline const *sp,
                                                             double x);
    double*             go_cspline_get_values               (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);
    double*             go_cspline_get_derivs               (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);
    double*             go_cspline_get_integrals            (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);

## Description

## Details

### GOCSpline

    typedef struct {
    	double const *x, *y;
    	double *a, *b, *c;
    	int n;
    } GOCSpline;

### enum GOCSplineType

    typedef enum {
    	GO_CSPLINE_NATURAL,
    	GO_CSPLINE_PARABOLIC,
    	GO_CSPLINE_CUBIC,
    	GO_CSPLINE_CLAMPED,
    	GO_CSPLINE_MAX
    } GOCSplineType;

### go_cspline_init ()

    GOCSpline*          go_cspline_init                     (double const *x,
                                                             double const *y,
                                                             int n,
                                                             unsigned  limits,
                                                             double c0,
                                                             double cn);

Creates a spline structure, and computes the coefficients associated with the polynoms. The ith polynome (between x[i-1] and x[i] is: y(x) = y[i-1] + (c[i-1] + (b[i-1] + a[i] * (x - x[i-1])) * (x - x[i-1])) * (x - x[i-1]) where a[i-1], b[i-1], c[i-1], x[i-1] and y[i-1] are the corresponding members of the new structure.

`x` : | the x values
`y` : | the y values
`n` : | the number of x and y values
`limits` : | how the limits must be treated, four values are allowed: GO_CSPLINE_NATURAL: first and least second derivatives are 0. GO_CSPLINE_PARABOLIC: the curve will be a parabole arc outside of the limits. GO_CSPLINE_CUBIC: the curve will be cubic outside of the limits. GO_CSPLINE_CLAMPED: the first and last derivatives are imposed.
`c0` : | the first derivative when using clamped splines, not used in the other limit types.
`cn` : | the first derivative when using clamped splines, not used in the other limit types.
Returns : | a newly created GOCSpline instance which should be destroyed by a call to go_bezier_spline_destroy.

### go_cspline_destroy ()

    void                go_cspline_destroy                  (GOCSpline *sp);

Frees the spline structure when done.

`sp` : | a spline structure returned by go_cspline_init.

### go_cspline_get_value ()

    double              go_cspline_get_value                (GOCSpline const *sp,
                                                             double x);

sp must be a valid spline structure as returned by go_cspline_init.

`sp` : | a spline structure returned by go_cspline_init.
`x` : | The value
Returns : | the interpolated value for x, or 0 if an error occurred.

### go_cspline_get_deriv ()

    double              go_cspline_get_deriv                (GOCSpline const *sp,
                                                             double x);

sp must be a valid spline structure as returned by go_cspline_init.

`sp` : | a spline structure returned by go_cspline_init.
`x` : | the value
Returns : | the interpolated derivative at x, or 0 if an error occurred.

### go_cspline_get_values ()

    double*             go_cspline_get_values               (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);

sp must be a valid spline structure as returned by go_cspline_init. The x values must be sorted in increasing order.

`sp` : | a spline structure returned by go_cspline_init.
`x` : | a vector a values at which interpolation is requested.
`n` : | the number of interpolation requested.
Returns : | a newly allocated array of interpolated values which should be destroyed by a call to g_free when not anymore needed, or NULL if an error occurred.

### go_cspline_get_derivs ()

    double*             go_cspline_get_derivs               (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);

sp must be a valid spline structure as returned by go_cspline_init. The x values must be sorted in increasing order.

`sp` : | a spline structure returned by go_cspline_init.
`x` : | a vector a values at which interpolation is requested.
`n` : | the number of interpolation requested.
Returns : | a newly allocated array of the n interpolated derivatives which should be destroyed by a call to g_free when not anymore needed, or NULL if an error occurred.

### go_cspline_get_integrals ()

    double*             go_cspline_get_integrals            (GOCSpline const *sp,
                                                             double const *x,
                                                             int n);

sp must be a valid spline structure as returned by go_cspline_init. The x values must be sorted in increasing order.

`sp` : | a spline structure returned by go_cspline_init.
`x` : | a vector a values at which interpolation is requested.
`n` : | the number of interpolation requested.
Returns : | a newly allocated array of the n-1 integrals on the intervals between two consecutive values stored in x. which should be destroyed by a call to g_free when not anymore needed, or NULL if an error occurred.