# spline VEX function

Returns an interpolated value along a polyline or spline curve.

## Overview

This function returns the value at a certain point t along a polyline or cubic spline specified by uniformly spaced control points.

The spline must always have uniform keys (that is, the key values must be spaces evenly along the length of the spline). To specify non-uniform control points (that is, to specify both the “x” and the “y” of the control points), use kspline.

1. float spline(string basis; float t; float v0, ...)

2. vector spline(string basis; float t; vector v0, ...)

3. vector4 spline(string basis; float t; vector4 v0, ...)

These forms take a variable number of arguments to specify the key values of the spline.

### Single basis, array of keys

1. float spline(string basis, float coord, float [] array)

2. vector spline(string basis; float coord; vector [] array)

3. vector4 spline(string basis; float coord; vector4 [] array)

These forms take a single string specifying the interpolation basis for all keys, and an array of key values.

### Array of bases and keys

1. float spline(string [] bases, float coord, float [] array)

2. vector spline(string [] bases; float coord; vector [] array)

3. vector4 spline(string [] bases; float coord; vector4 [] array)

These forms take an array of strings specifying the interpolation bases between the keys, and array of key values.

## Linear

When basis is "linear", this function connects the control point values with a polyline.

For example, if you specified four values:

spline("linear", t, v0, v1, v2, v3)

…the function returns the height of the orange dot at position t.

## Cubic spline

When basis is "cubic", "catrom", or "catmull-rom", this function connects the point values with a Catmull-Rom spline.

Note that the first and last values are outside the sample area to provide the slope of the curve at the second point (at the start of the sample range) and the second-to-last point (at the end of the sample range).

For example, if you specified six values:

spline("catrom", t, v0, v1, v2, v3, v4, v5)

…the function returns the height of the orange dot at position t.

(This image is for illustration only, it does not show the correct curve for the shown points.)

## Linear solve

When basis is "linearsolve", this function maps between a set of non-uniform positions and a set of values. The kspline function does this mapping implicitly.

tk = spline("linearsolve", t, k0, k1, k2, k3, ...);
v = spline(basis, tk, v1, v2, v3, ...);

(Technically, linearsolve interprets the values as key values, solves the intersection of the spline, and returns the intercept point.)