Esempio n. 1
0
            protected void UpdateInterpolation()
            {
                int count = _keyFrames.Count;
                var xs    = new double[count];
                var ys    = new double[count];

                for (int i = 0; i < count; ++i)
                {
                    xs[i] = (double)_keyFrames[i].time;
                    ys[i] = (double)_keyFrames[i].value;
                }
                if (count <= 1)
                {
                    _interpolation = StepInterpolation.Interpolate(xs, ys);
                }
                else if (count <= 2)
                {
                    _interpolation = LinearSpline.Interpolate(xs, ys);
                }
                else if (count <= 3)
                {
                    _interpolation = MathNet.Numerics.Interpolate.Polynomial(xs, ys);
                }
                else if (count <= 4)
                {
                    _interpolation = CubicSpline.InterpolateNatural(xs, ys);
                }
                else
                {
                    _interpolation = CubicSpline.InterpolateAkima(xs, ys);
                }
            }
        public void FitsAtSamplePoints()
        {
            IInterpolation ip = new StepInterpolation(_t, _y);

            for (int i = 0; i < _y.Length; i++)
            {
                Assert.AreEqual(_y[i], ip.Interpolate(_t[i]), "A Exact Point " + i);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Create a step-interpolation based on arbitrary points.
 /// </summary>
 /// <param name="points">The sample points t.</param>
 /// <param name="values">The sample point values x(t).</param>
 /// <returns>
 /// An interpolation scheme optimized for the given sample points and values,
 /// which can then be used to compute interpolations and extrapolations
 /// on arbitrary points.
 /// </returns>
 /// <remarks>
 /// if your data is already sorted in arrays, consider to use
 /// MathNet.Numerics.Interpolation.StepInterpolation.InterpolateSorted
 /// instead, which is more efficient.
 /// </remarks>
 public static IInterpolation Step(IEnumerable <double> points, IEnumerable <double> values)
 {
     return(StepInterpolation.Interpolate(points, values));
 }
 public virtual double Interpolate_Step(double[] x, double[] y, double xValue)
 {
     return(StepInterpolation.Interpolate(x, y).Interpolate(xValue));
 }
 public void FewSamples()
 {
     Assert.That(() => StepInterpolation.Interpolate(new double[0], new double[0]), Throws.ArgumentException);
     Assert.That(StepInterpolation.Interpolate(new[] { 1.0 }, new[] { 2.0 }).Interpolate(1.0), Is.EqualTo(2.0));
 }