Example usage for org.apache.commons.math3.analysis.interpolation PiecewiseBicubicSplineInterpolator interpolate

List of usage examples for org.apache.commons.math3.analysis.interpolation PiecewiseBicubicSplineInterpolator interpolate

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.interpolation PiecewiseBicubicSplineInterpolator interpolate.

Prototype

public PiecewiseBicubicSplineInterpolatingFunction interpolate(final double[] xval, final double[] yval,
        final double[][] fval) throws DimensionMismatchException, NullArgumentException, NoDataException,
        NonMonotonicSequenceException 

Source Link

Usage

From source file:org.apache.solr.client.solrj.io.eval.BicubicSplineEvaluator.java

@Override
public Object doWork(Object... objects) throws IOException {

    if (objects.length != 3) {
        throw new IOException(
                "The bicubicSpline function requires three paremeters," + objects.length + " found.");
    }/* w ww .java  2s . com*/

    Object first = objects[0];
    Object second = objects[1];
    Object third = objects[2];

    double[] x = null;
    double[] y = null;
    double[][] grid = null;

    if (first instanceof List && second instanceof List && third instanceof Matrix) {
        List<Number> xlist = (List<Number>) first;
        x = new double[xlist.size()];

        for (int i = 0; i < x.length; i++) {
            x[i] = xlist.get(i).doubleValue();
        }

        List<Number> ylist = (List<Number>) second;
        y = new double[ylist.size()];

        for (int i = 0; i < y.length; i++) {
            y[i] = ylist.get(i).doubleValue();
        }

        Matrix matrix = (Matrix) third;
        grid = matrix.getData();

        PiecewiseBicubicSplineInterpolator interpolator = new PiecewiseBicubicSplineInterpolator();
        BivariateFunction bivariateFunction = interpolator.interpolate(x, y, grid);
        return bivariateFunction;
    } else {
        throw new IOException(
                "The bicubicSpline function expects two numeric arrays and a matrix as parameters.");
    }
}