I am working with a dataset consisting of yearly data. Each item in the array corresponds to a year. I would to extend this dataset and make it monthly instead. I have been researching about it and trying different methods but in the end, finding De Casteljau’s algorithm to determine individual points at a Bezier curve.
https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm
If you can take a look at the example here. http://jsfiddle.net/vdbhc98j/
const data = [29.9, 55.5, 106.4, 1129.2, 344.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];
// https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm
const getLinearInterpolatedValue = (t: number, p1: number, p2: number) => (1 - t) * p1 + t * p2;
const getLinearInterpolatedSegment = (...args: number[]): number[] => {
const [t, p1, p2, ...rest] = args;
return rest.length > 0
? [getLinearInterpolatedValue(t, p1, p2), ...getLinearInterpolatedSegment(t, p2, ...rest)]
: [getLinearInterpolatedValue(t, p1, p2)];
};
const findPointOnBezierCurve = (t: number, ps: number[]): number =>
ps.length > 1 ? findPointOnBezierCurve(t, getLinearInterpolatedSegment(t, ...ps)) : ps[0];
const subdividePoints = (points: number[], years: number) => {
if (points.length === 0 || years === 0) {
return points;
}
const step = 1 / years / 12;
const newPoints = [];
for (let i = 0; i <= years * 12; i++) {
newPoints.push(findPointOnBezierCurve(step * i, points));
}
return newPoints;
};
const chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'spline'
},
series: [{
data,
}, {
type: 'spline',
data: []
}]
});
const subdivided = new Highcharts.Chart({
chart: {
renderTo: 'container2',
type: 'spline'
},
series: [{
data: subdividePoints(data, 10)
}, {
type: 'spline',
data: []
}]
});
It is indeed subdividing the curve into 120 distinct points even though the resemblance is there, it is not exactly maintaining the curve.
If you also inspect the values, within the original chart without subdivision, the value goes up to 1129, whereas in the subdivided one it is up to ~427.
Could you please help me - specifically what I am expecting from the algorithm is wrong or I am making a mistake somewhere? If you could point out if there are alternatives to this problem, that’d be great.
Thank you in advance.

