Ejemplo n.º 1
0
        public void TestInterpolationMethod_AkimaSpline()
        {
            double[] t = new double[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
            double[] x = new double[] { 1.0, 2.0, -1.0, 0.0, 1.0 };

            IInterpolationMethod method = Interpolation.CreateAkimaCubicSpline(t, x);

            Assert.IsInstanceOfType(typeof(AkimaSplineInterpolation), method, "Type");

            for (int i = 0; i < t.Length; i++)
            {
                // verify the interpolated values exactly at the sample points.
                Assert.AreEqual(x[i], method.Interpolate(t[i]), "A Exact Point " + i.ToString());
            }

            // TODO: Verify the expected values (that they are really the expected ones)
            NumericAssert.AreAlmostEqual(-0.52, method.Interpolate(-2.4), 1e-15, "A -2.4");
            NumericAssert.AreAlmostEqual(1.826, method.Interpolate(-0.9), 1e-15, "A -0.9");
            NumericAssert.AreAlmostEqual(0.25, method.Interpolate(-0.5), 1e-15, "A -0.5");
            NumericAssert.AreAlmostEqual(-1.006, method.Interpolate(-0.1), 1e-15, "A -0.1");
            NumericAssert.AreAlmostEqual(-0.9, method.Interpolate(0.1), 1e-15, "A 0.1");
            NumericAssert.AreAlmostEqual(-0.6, method.Interpolate(0.4), 1e-15, "A 0.4");
            NumericAssert.AreAlmostEqual(0.2, method.Interpolate(1.2), 1e-15, "A 1.2");
            NumericAssert.AreAlmostEqual(9, method.Interpolate(10.0), 1e-14, "A 10.0");
            NumericAssert.AreAlmostEqual(-151, method.Interpolate(-10.0), 1e-14, "A -10.0");
        }
Ejemplo n.º 2
0
        private List <Position> GetPoints(List <Position> points, int type)
        {
            try
            {
                List <Position>      result = new List <Position>();
                IInterpolationMethod method = null;
                List <double>        xs     = new List <double>();
                List <double>        ys     = new List <double>();
                if (type > 0)
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        xs.Add(points[i].X);
                        ys.Add(points[i].Z);
                    }
                }

                if (type == 0)
                {
                    result.AddRange(points);
                }
                else if (type == 1)
                {
                    method = Interpolation.CreateNaturalCubicSpline(xs, ys);
                }
                else if (type == 2)
                {
                    method = Interpolation.CreateAkimaCubicSpline(xs, ys);
                }

                if (method != null)
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        Position p1 = points[i];
                        Position p2 = points[i + 1];
                        double   x  = (p1.X + p2.X) / 2;
                    }
                }

                return(result);
            }
            catch (System.Exception ex)
            {
                Log.Error(hisTag, "GetPoints", "Exception:" + ex);
                return(null);
            }
        }
        public void TestInterpolationMethod_AkimaSpline()
        {
            double[] t = new double[] { -2.0, -1.0, 0.0, 1.0, 2.0 };
            double[] x = new double[] { 1.0, 2.0, -1.0, 0.0, 1.0 };

            IInterpolationMethod method = Interpolation.CreateAkimaCubicSpline(t, x);

            Assert.That(method, Is.TypeOf(typeof(AkimaSplineInterpolation)), "Type");

            for (int i = 0; i < t.Length; i++)
            {
                // verify the interpolated values exactly at the sample points.
                Assert.That(method.Interpolate(t[i]), Is.EqualTo(x[i]), "A Exact Point " + i.ToString());
            }

            // TODO: Verify the expected values (that they are really the expected ones)
            Assert.That(method.Interpolate(-2.4), NumericIs.AlmostEqualTo(-0.52, 1e-15), "A -2.4");
            Assert.That(method.Interpolate(-0.9), NumericIs.AlmostEqualTo(1.826, 1e-15), "A -0.9");
            Assert.That(method.Interpolate(-0.5), NumericIs.AlmostEqualTo(0.25, 1e-15), "A -0.5");
            Assert.That(method.Interpolate(-0.1), NumericIs.AlmostEqualTo(-1.006, 1e-15), "A -0.1");
            Assert.That(method.Interpolate(0.1), NumericIs.AlmostEqualTo(-0.9, 1e-15), "A 0.1");
            Assert.That(method.Interpolate(0.4), NumericIs.AlmostEqualTo(-0.6, 1e-15), "A 0.4");
            Assert.That(method.Interpolate(1.2), NumericIs.AlmostEqualTo(0.2, 1e-15), "A 1.2");
            Assert.That(method.Interpolate(10.0), NumericIs.AlmostEqualTo((double)9, 1e-14), "A 10.0");
            Assert.That(method.Interpolate(-10.0), NumericIs.AlmostEqualTo((double)(-151), 1e-14), "A -10.0");

            // Test Linear Case
            for (int k = 2; k < 6; k++)
            {
                double[] linx, liny, linxtest, linytest;
                BuildLinearCase(2, k + 4, out linx, out liny, out linxtest, out linytest);
                IInterpolationMethod linearMethod = Interpolation.CreateAkimaCubicSpline(linx, liny);
                for (int i = 0; i < linxtest.Length; i++)
                {
                    Assert.That(linearMethod.Interpolate(linxtest[i]), NumericIs.AlmostEqualTo(linytest[i], 1e-12), String.Format("Linear k={0} i={1}", k, i));
                }
            }
        }