cubic-spline
cubic-spline copied to clipboard
NaN for Values Higher than Max Known Point
I expected for this library to calculate values beyond the known maximum. If that is a valid expectation, either I'm doing something wrong or it's returning NaN
for higher values.
https://jsfiddle.net/s0vr6zp1/1/
import Spline from 'https://cdn.skypack.dev/[email protected]';
const knownPoints = [{
x: 4,
y: 536
}, {
x: 6,
y: 634
}, {
x: 8,
y: 713
}, {
x: 10,
y: 782
}, {
x: 12,
y: 843
}, {
x: 14,
y: 898
}, {
x: 16,
y: 949
}, {
x: 18,
y: 996
}, {
x: 20,
y: 1040
}, {
x: 22,
y: 1081
}, {
x: 24,
y: 1121
}];
const knownXs = knownPoints.map(function(hash) {
return hash.x;
});
const knownYs = knownPoints.map(function(hash) {
return hash.y;
});
const spline = new Spline(knownXs, knownYs);
console.log("spline at 1: " +spline.at(1));
console.log("spline at 10: " +spline.at(10));
console.log("spline at 30: " +spline.at(30));
Yields:
spline at 1: 397.438082390494
spline at 10: 782
spline at 30: NaN