

Ask HN: Is it possible to extract the formula for a spline function in Java - sgy

Is there anyway to describe the PolynomialSplineFunction[1], or any other spline function in java, by a single formula [y = f(x)]?<p>[1] http:&#x2F;&#x2F;commons.apache.org&#x2F;proper&#x2F;commons-math&#x2F;apidocs&#x2F;org&#x2F;apache&#x2F;commons&#x2F;math3&#x2F;analysis&#x2F;polynomials&#x2F;PolynomialSplineFunction.html
======
logn
Here's code I have for a quadratic spline. It loops through each x-axis value
and stores y-values in an array. There are three inputs assumed to be given,
points: (x0,y0) (x1,y1) (x2,y2). I license this snippet as Public Domain.

    
    
            double a = (x0 * (y1 - y2) + y0 * (x2 - x1) + (x1 * y2) - (x2 * y1)) / ((x1 - x0) * (x2 - x0) * (x2 - x1));
            double b = ((y2 - y0) / (x2 - x0)) - (x2 + x0) * a;
            double c = y0 - (a * (x0 * x0)) - b * x0;
            for (int xCount = (int) Math.rint(x0); xCount < (int) Math.rint(x2); xCount++) {
                wave[xCount] = (a * (xCount * xCount) + b * xCount + c);
            }

