3 ms·
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, point
by logn 12y ago
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);
}