예제 #1
0
        internal override void GenerateCurve()
        {
            //create the senseCurve, the start of the curve and start populating it with random values
            List <SensitivityPoint> sensCurve  = new List <SensitivityPoint>();
            SensitivityPoint        firstPoint = new SensitivityPoint(0, sensMean);

            sensCurve.Add(firstPoint);
            Random rnd = new Random();

            for (double timecode = curveTimestep; timecode < this.lenght; timecode += curveTimestep)
            {
                double sensDirection = rnd.NextDouble();                                              //create a random double to determine if sense is going to be faster or slower
                if (sensDirection >= 0.5)                                                             //sens will be faster
                {
                    double           randomSens = sensMean + rnd.NextDouble() * (sensMax - sensMean); //generates a random value in the range of (basesens:maxsens)
                    SensitivityPoint sensPoint  = new SensitivityPoint(timecode, randomSens);
                    sensCurve.Add(sensPoint);
                }
                else // sensDirection <0.5 -> sens will be slower
                {
                    double           randomSens = sensMin + rnd.NextDouble() * (sensMean - sensMin);
                    SensitivityPoint sensPoint  = new SensitivityPoint(timecode, randomSens);
                    sensCurve.Add(sensPoint);
                }
            }
            SensitivityPoint finalSensPoint = new SensitivityPoint(this.lenght, 1);//Make sure the curve ends at base sens

            sensCurve.Add(finalSensPoint);
            base.sensCurve = sensCurve;
        }
예제 #2
0
        public void InterpolateCurvePchip()
        {
            List <SensitivityPoint> smoothCurve = new List <SensitivityPoint>();

            double[]    timestamp   = sensCurve.Select(sensCurve => sensCurve.timeStamp).ToArray();
            double[]    randomsense = sensCurve.Select(sensCurve => sensCurve.sensitivity).ToArray();
            CubicSpline spline      = CubicSpline.InterpolatePchip(timestamp, randomsense);

            for (double timecode = 0; timecode < this.lenght; timecode += timestep)
            {
                SensitivityPoint sensPoint = new SensitivityPoint(timecode, spline.Interpolate(timecode));
                smoothCurve.Add(sensPoint);
            }
            sensCurve = smoothCurve;
        }