Init( IList <double> t, IList <double> x ) { if (null == t) { throw new ArgumentNullException("t"); } if (null == x) { throw new ArgumentNullException("x"); } if (t.Count < 2) { throw new ArgumentOutOfRangeException("t"); } if (t.Count != x.Count) { throw new ArgumentException(Properties.Resources.ArgumentVectorsSameLengths); } double[] c = new double[4 * (t.Count - 1)]; double[] tt = new double[t.Count]; t.CopyTo(tt, 0); double[] xx = new double[x.Count]; x.CopyTo(xx, 0); Sorting.Sort(tt, xx); for (int i = 0, j = 0; i < tt.Length - 1; i++, j += 4) { c[j] = xx[i]; c[j + 1] = (xx[i + 1] - xx[i]) / (tt[i + 1] - tt[i]); c[j + 2] = 0; c[j + 3] = 0; } _spline.Init(tt, c); }
InitInternal( double[] t, double[] x, double[] d) { double[] c = new double[4 * (t.Length - 1)]; for (int i = 0, j = 0; i < t.Length - 1; i++, j += 4) { double delta = t[i + 1] - t[i]; double delta2 = delta * delta; double delta3 = delta * delta2; c[j] = x[i]; c[j + 1] = d[i]; c[j + 2] = ((3 * (x[i + 1] - x[i])) - (2 * d[i] * delta) - (d[i + 1] * delta)) / delta2; c[j + 3] = ((2 * (x[i] - x[i + 1])) + (d[i] * delta) + (d[i + 1] * delta)) / delta3; } _spline.Init(t, c); }