FileDocCategorySizeDatePackage
Spline.javaAPI DocAndroid 5.1 API10207Thu Mar 12 22:22:10 GMT 2015android.util

Spline

public abstract class Spline extends Object
Performs spline interpolation given a set of control points.
hide

Fields Summary
Constructors Summary
Methods Summary
public static android.util.SplinecreateLinearSpline(float[] x, float[] y)
Creates a linear spline from a given set of control points. Like a monotone cubic spline, the interpolated curve will be monotonic if the control points are monotonic.

param
x The X component of the control points, strictly increasing.
param
y The Y component of the control points.
return
throws
IllegalArgumentException if the X or Y arrays are null, have different lengths or have fewer than 2 values.
throws
IllegalArgumentException if the X components of the control points are not strictly increasing.

        return new LinearSpline(x, y);
    
public static android.util.SplinecreateMonotoneCubicSpline(float[] x, float[] y)
Creates a monotone cubic spline from a given set of control points. The spline is guaranteed to pass through each control point exactly. Moreover, assuming the control points are monotonic (Y is non-decreasing or non-increasing) then the interpolated values will also be monotonic. This function uses the Fritsch-Carlson method for computing the spline parameters. http://en.wikipedia.org/wiki/Monotone_cubic_interpolation

param
x The X component of the control points, strictly increasing.
param
y The Y component of the control points, monotonic.
return
throws
IllegalArgumentException if the X or Y arrays are null, have different lengths or have fewer than 2 values.
throws
IllegalArgumentException if the control points are not monotonic.

        return new MonotoneCubicSpline(x, y);
    
public static android.util.SplinecreateSpline(float[] x, float[] y)
Creates an appropriate spline based on the properties of the control points. If the control points are monotonic then the resulting spline will preserve that and otherwise optimize for error bounds.

        if (!isStrictlyIncreasing(x)) {
            throw new IllegalArgumentException("The control points must all have strictly "
                    + "increasing X values.");
        }

        if (isMonotonic(y)) {
            return createMonotoneCubicSpline(x, y);
        } else {
            return createLinearSpline(x, y);
        }
    
public abstract floatinterpolate(float x)
Interpolates the value of Y = f(X) for given X. Clamps X to the domain of the spline.

param
x The X value.
return
The interpolated Y = f(X) value.

private static booleanisMonotonic(float[] x)

        if (x == null || x.length < 2) {
            throw new IllegalArgumentException("There must be at least two control points.");
        }
        float prev = x[0];
        for (int i = 1; i < x.length; i++) {
            float curr = x[i];
            if (curr < prev) {
                return false;
            }
            prev = curr;
        }
        return true;
    
private static booleanisStrictlyIncreasing(float[] x)

        if (x == null || x.length < 2) {
            throw new IllegalArgumentException("There must be at least two control points.");
        }
        float prev = x[0];
        for (int i = 1; i < x.length; i++) {
            float curr = x[i];
            if (curr <= prev) {
                return false;
            }
            prev = curr;
        }
        return true;