kspline VEX function

Returns an interpolated value along a spline curve.

See also: spline

Overview

  1. float kspline(string basis; float t; float v0, float k0, ...)

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

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

This function returns the value at a certain point t along a polyline or cubic spline specified by pairs of v (height) and k (position).

Tip

To specify uniform control points (that is, to only specify values and have the function distribute them uniformly), use spline.

This function is the equivalent of:

type kspline(basis, t, v0, k0, v1, k1, v2, k2...)
{
    float tk = spline("linearsolve", t, k0, k1, k2, ...);
    return spline(basis, tk, v0, v1, v2, ...);
}

Linear

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

For example, if you specified four v/k pairs:

…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 v/k pairs:

…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.)