예제 #1
0
        ///<summary>Apply boundary conditions (add extra sectios)
        /// to match specified slopes slope1 and slope2.</summary>
        public void ApplyExtraSlope(double slope1, double slope2)
        {
            // Create list of existing spline sections.
            List <ClSplineCubicSection> listSection = new List <ClSplineCubicSection>(splineSections_);

            // Add extra sections at the beginning.
            double extraStep = h_.First();

            ClSplineCubicSection[] extraCubicSmoothSectionBegin = listSection[0].Extend(slope1, extraStep);
            for (int i = 2; i >= 0; i--)
            {
                listSection.Insert(0, extraCubicSmoothSectionBegin[i]);
            }

            // Add extra sections at the end (this is less trivial).
            // First calculate negative extra step.
            extraStep = -h_.Last();
            ClSplineCubicSection cubicSmoothSectionLast = listSection[listSection.Count - 2];

            // Re-reference last spline section.
            cubicSmoothSectionLast.ChangeStartPoint(listSection.Last().X, listSection.Last().Y);
            // Obtain needed extra sections.
            ClSplineCubicSection[] extraCubicSmoothSectionEnd = cubicSmoothSectionLast.Extend(slope2, extraStep);
            // And re-reference them all back.
            ClSplineCubicSection cubicSmoothSectionTail = new ClSplineCubicSection
            {
                X = extraCubicSmoothSectionEnd[0].X,
                Y = extraCubicSmoothSectionEnd[0].Y
            };

            extraCubicSmoothSectionEnd[0].ChangeStartPoint(extraCubicSmoothSectionEnd[1].X, extraCubicSmoothSectionEnd[1].Y);
            extraCubicSmoothSectionEnd[1].ChangeStartPoint(extraCubicSmoothSectionEnd[2].X, extraCubicSmoothSectionEnd[2].Y);
            extraCubicSmoothSectionEnd[2].ChangeStartPoint(listSection[listSection.Count - 1].X, listSection[listSection.Count - 1].Y);
            // Finally, remove arteficial last section and add new ones.
            listSection.RemoveAt(listSection.Count - 1);
            for (int i = 2; i >= 0; i--)
            {
                listSection.Add(extraCubicSmoothSectionEnd[i]);
            }
            listSection.Add(cubicSmoothSectionTail);

            // Update field splineSections_.
            splineSections_ = listSection.ToArray();
        }
예제 #2
0
        /// <summary> Spline initialisation from X, Y input arrays.
        /// u is array of uncertainties.
        /// X must be in ascending order. </summary>
        virtual public void Load(ClWeightedPoint[] data, Spline1DBuilder parameters = null)
        {
            // Number of points.
            pointsNumber_ = data.Length;

            // Number of unknown b_i.
            equationSize_ = pointsNumber_ - 2;

            // Initialise spline sections (input points are (x_0, y_0), ..., (x_n, y_n)).
            splineSections_ = new ClSplineCubicSection[pointsNumber_];
            for (int i = 0; i < pointsNumber_; ++i)
            {
                splineSections_[i] = new ClSplineCubicSection {
                    X = data[i].X[0], Y = data[i].Value, Weight = 1
                };
                // TODO Fix NaN problem with weigths.
                //splineSections_[i].Weight = data[i].Weight;
            }

            // Calculate spline helper variables.
            CalculateHelperVariables();
        }