コード例 #1
0
        /// <summary>
        /// <para> 1. Load thrust data (time, force). </para>
        /// <para> 2. Generate interpolated thrust curve. </para>
        /// </summary>
        public IInterpolation LoadThrust()
        {
            var            timeList  = new List <double>();
            var            forceList = new List <double>();
            IInterpolation intpThrust;

            StreamReader sr            = new StreamReader(FilePath, Encoding.GetEncoding("SHIFT_JIS"));
            var          fileExtension = System.IO.Path.GetExtension(FilePath);

            // Open thrust file.
            while (sr.EndOfStream == false)
            {
                string   line      = sr.ReadLine();
                string[] splitData = null;

                if (fileExtension == ".txt")
                {
                    splitData = line.Split('\t');
                }
                else if (fileExtension == ".csv")
                {
                    splitData = line.Split(',');
                }

                // Omit comment lines
                if (double.TryParse(splitData[0], out double time) &&
                    double.TryParse(splitData[1], out double force))
                {
                    timeList.Add(time);
                    forceList.Add(force);
                }
            }

            // Convert List to Array.
            int listLen = timeList.Count;

            timeArray  = new double[listLen];
            forceArray = new double[listLen];

            timeArray  = timeList.ToArray();
            forceArray = forceList.ToArray();

            // Select interpolation method.
            switch (IntpMethod)
            {
            case "linear":
                intpThrust = Interpolate.Linear(timeArray, forceArray);
                break;

            case "cubic":
                intpThrust = Interpolate.CubicSpline(timeArray, forceArray);
                break;

            default:
                intpThrust = Interpolate.Linear(timeArray, forceArray);
                break;
            }

            return(intpThrust);
        }
コード例 #2
0
        private void CalculateCoefficients()
        {
            int quantity = PointsContainer.PlotPoints.Points.Count;

            double[] x       = new double[quantity];
            double[] y       = new double[quantity];
            int      counter = 0;

            foreach (DataPoint Point in PointsContainer.PlotPoints.Points)
            {
                x[counter] = Point.X;
                y[counter] = Point.Y;
                counter++;
            }
            IInterpolation cubicSpline = Interpolate.CubicSpline(x, y);

            for (double i = this.AxisMinimum; i < this.AxisMaximum; i += this.Step)
            {
                PointsContainer.PolynomSeries.Points.Add(new DataPoint(i, cubicSpline.Interpolate(i)));
            }
        }
コード例 #3
0
        private void SetIntpThrust(List <double> timeList, List <double> forceList)
        {
            var dataNum    = timeList.Count;
            var timeArray  = timeList.ToArray();
            var forceArray = forceList.ToArray();

            // Select interpolation method.
            switch (IntpMethod)
            {
            case "linear":
                IntpThrust = Interpolate.Linear(timeArray, forceArray);
                break;

            case "cubic":
                IntpThrust = Interpolate.CubicSpline(timeArray, forceArray);
                break;

            default:
                IntpThrust = Interpolate.Linear(timeArray, forceArray);
                break;
            }
        }