diff --git a/core/src/main/kotlin/core/math/Interpolators.kt b/core/src/main/kotlin/core/math/Interpolators.kt index f303fdef1c..90ebc68142 100644 --- a/core/src/main/kotlin/core/math/Interpolators.kt +++ b/core/src/main/kotlin/core/math/Interpolators.kt @@ -54,15 +54,19 @@ class CubicSplineInterpolator(val xs: DoubleArray, val ys: DoubleArray) { val segmentMap = TreeMap() for (i in 0..n - 1) { - val coefficients = doubleArrayOf(ys[i], b[i], c[i], d[i]) + val coefficients = doubleArrayOf(d[i], c[i], b[i], ys[i]) segmentMap.put(xs[i], Polynomial(coefficients)) } return SplineFunction(segmentMap) } } +/** + * Represents a polynomial function of arbitrary degree + * @param coefficients polynomial coefficients in descending order (highest degree first) + */ class Polynomial(private val coefficients: DoubleArray) { - fun getValue(x: Double) = coefficients.reversed().fold(0.0, { result, c -> result * x + c }) + fun getValue(x: Double) = coefficients.fold(0.0, { result, c -> result * x + c }) } /**