calculateCurve function
Implementation
List<CurvePoint> calculateCurve(List<DataPoint> dataPoints) {
List<CurvePoint> curve = [];
int numPoints = dataPoints.length;
double x1, x2, x3, y1, y2, y3, a, b, c;
double rate =
(dataPoints[1].B - dataPoints[0].B) / (dataPoints[1].A - dataPoints[0].A);
curve.add(
CurvePoint(A: 0, B: rate, C: dataPoints[0].B - dataPoints[0].A * rate));
for (int i = 1; i < numPoints - 1; i++) {
x1 = dataPoints[i - 1].A;
x2 = dataPoints[i].A;
x3 = dataPoints[i + 1].A;
y1 = dataPoints[i - 1].B;
y2 = dataPoints[i].B;
y3 = dataPoints[i + 1].B;
a = ((y3 - y1) * (x2 - x1) - (y2 - y1) * (x3 - x1)) /
((x3 * x3 - x1 * x1) * (x2 - x1) - (x2 * x2 - x1 * x1) * (x3 - x1));
b = (y2 - y1 - a * (x2 * x2 - x1 * x1)) / (x2 - x1);
c = y1 - (a * x1 * x1 + b * x1);
curve.add(CurvePoint(A: a, B: b, C: c));
}
curve.add(CurvePoint(A: 0, B: 0, C: dataPoints[numPoints - 1].B));
return curve;
}