Exemplo n.º 1
0
        private static IInterpolation GetInterpolator(ColorInterpolation interpolation, double[] x, double[] y)
        {
            switch (interpolation)
            {
            case ColorInterpolation.Akima:
                return(CubicSpline.InterpolateAkimaSorted(x, y));

            case ColorInterpolation.Spline:
                return(CubicSpline.InterpolateNaturalSorted(x, y));

            case ColorInterpolation.Linear:
                return(LinearSpline.InterpolateSorted(x, y));

            default:
                throw new ArgumentException("interpolation");
            }
        }
Exemplo n.º 2
0
        public DemoModeBrake()
        {
            Debug.LogToFileMethod();

            sample = new DemoSample(0, 0, 0, 0, 0, 0);

            /*
             * Profil Brake: (nur Zeitangabe, keine Streckenangabe)
             * Anzeige geht auf 175kmh und wieder zurück auf 0kmh
             * - 100-0: 3,6s
             */

            // BRAKE
            // accelerate to 175 km/h and then back to 0 km/h
            double[] pointsX = { 0, 2, 4, 6, 8, 10, 12, 13, 14, 15, TIME_MAX };         // time  [s]
            double[] pointsY = { 0, 33, 66, 100, 140, 175, 100, 75, 50, 25, 0 };        // speed [km/h]

            spline = CubicSpline.InterpolateAkimaSorted(pointsX, pointsY);
        }
Exemplo n.º 3
0
        public void InterpolateAkimaSorted_MustBeThreadSafe_GitHub219([Values(8, 32, 256, 1024)] int samples)
        {
            var x = Generate.LinearSpaced(samples + 1, 0.0, 2.0 * Math.PI);
            var y = new double[samples][];

            for (var i = 0; i < samples; ++i)
            {
                y[i] = x.Select(xx => Math.Sin(xx) / (i + 1)).ToArray();
            }

            var yipol = new double[samples];

            System.Threading.Tasks.Parallel.For(0, samples, i =>
            {
                var spline = CubicSpline.InterpolateAkimaSorted(x, y[i]);
                yipol[i]   = spline.Interpolate(1.0);
            });

            CollectionAssert.DoesNotContain(yipol, double.NaN);
        }
        public DemoModeAcceleration()
        {
            Debug.LogToFileMethod();

            sample = new DemoSample(0, 0, 0, 0, 0, 0);

            /*
             * Profil Acceleration:
             * Anzeige geht auf 250kmh und wieder zurück auf 0kmh
             * 0-100: 3,8s
             * 0-200: 10,3s
             */

            // ACCELERATION
            // accelerate to 250 km/h and then back to 0 km/h
            double[] pointsX = { 0, 1, 4.6, 13.5, 15, TIME_MAX }; // time  [s]
            double[] pointsY = { 0, 30, 100, 250, 100, 0 };       // speed [km/h]

            spline = CubicSpline.InterpolateAkimaSorted(pointsX, pointsY);
        }
Exemplo n.º 5
0
        public DemoModeZeroToZero()
        {
            Debug.LogToFileMethod();

            sample = new DemoSample(0, 0, 0, 0, 0, 0);

            /*
             * Profil Zero to Zero: (nur Zeitangabe, keine Streckenangabe)
             * Geschwindigkeitsanzeige geht auf 126kmh und wieder zurück auf 0kmh
             * - 0-100: 4,85s
             * - 0-126 (Vmax): 6,2s
             * - 100-0: 3,75s
             * - 0 - 0: 10,85s
             */

            // ZERO TO ZERO
            // accelerate to 126 km/h and then back to 0 km/h
            double[] pointsX = { 0, 7, 8, 9, TIME_MAX };   // time  [s]
            double[] pointsY = { 0, 110, 126, 110, 0 };    // speed [km/h]

            spline = CubicSpline.InterpolateAkimaSorted(pointsX, pointsY);
        }
Exemplo n.º 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            show.addData(sample0.ToArray(), sample1.ToArray(), 0);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            var            x      = new double[Wnum];
            var            y      = new double[Wnum];
            IInterpolation spline = null;

            switch (cbM.SelectedIndex)
            {
            case 1:
                spline = CubicSpline.InterpolateAkimaSorted(sample0, sample1);
                break;

            default:
                spline = LinearSpline.Interpolate(sample0, sample1);
                break;
            }
            var Wdelta = (Wstop - Wstart) / Wnum;

            for (int i = 0; i < Wnum; i++)
            {
                y[i] = Wstart + i * Wdelta;
                x[i] = spline.Interpolate(y[i]);
            }
            sw.Stop();
            var tm = sw.ElapsedMilliseconds;

            show.addData(y, x, 1);

            var sb = new StringBuilder();

            sb.AppendLine("Time [ms] " + tm);

            Results = sb.ToString();
        }
Exemplo n.º 7
0
        private List <Wave> GetListOfWavesFromRange(DateTime StartDate, DateTime EndDate)
        {
            List <double> oPriceData = GetRangeOfDataAsDoubleIncludingLowHigh(StartDate, EndDate);

            if (oPriceData.Count < 5)
            {
                return(new List <Wave>());
            }

            CubicSpline oCSTotalData = CubicSpline.InterpolateAkimaSorted(

                oPriceData.Select((s, i2) => new { i2, s })
                .Select(t => Convert.ToDouble(t.i2)).ToArray(),

                oPriceData.Select(s => Convert.ToDouble(s)).ToArray());


            //create list of Waves
            List <Wave> oWaves = new List <Wave>();

            var FirstVarDiff = oPriceData.Select((s, i2) => new { i2, s })
                               .ToList().Select(f => oCSTotalData.Differentiate(Convert.ToDouble(f.i2))).ToArray();

            int           i                   = 0;
            Momentum      Current             = Momentum.Neutral;
            Momentum      Old                 = Momentum.Neutral;
            List <double> oCalcDoublesForWave = new List <double>();
            bool          bFirst              = true;

            foreach (var fvd in FirstVarDiff)
            {
                if (fvd < 0)
                {
                    Current = Momentum.Negative;
                }
                else if (fvd == 0)
                {
                    Current = Momentum.Neutral;
                }
                else
                {
                    Current = Momentum.Positive;
                }

                if (bFirst)
                {
                    oCalcDoublesForWave.Add(oCSTotalData.Interpolate(i));
                    bFirst = false;
                }
                else
                {
                    if (Current != Old && oCalcDoublesForWave.Count > 1)
                    {
                        oWaves.Add(new Wave
                        {
                            End         = oCalcDoublesForWave.Last(),
                            Start       = oCalcDoublesForWave.First(),
                            Length      = oCalcDoublesForWave.Count,
                            Momentum    = Old,
                            SourceIndex = i
                        });
                        oCalcDoublesForWave.Clear();
                    }
                    else if (Current != Old && oCalcDoublesForWave.Count <= 1)
                    {
                        oCalcDoublesForWave.Clear();
                    }
                    oCalcDoublesForWave.Add(oCSTotalData.Interpolate(i));
                }
                Old = Current;

                i++;
            }
            return(oWaves);
        }