Exemple #1
0
        /// <summary>
        /// 进行二维曲线的样条插值
        /// </summary>
        /// <param name="srcX">插值数据源中的X,X序列中的值不一定必须要递增或者递减排列</param>
        /// <param name="srcY">插值数据源中的Y</param>
        /// <param name="interpX">想要进行插值的x序列</param>
        /// <returns>插值后得到的与 <paramref name="interpX"/> 相对应的y值序列</returns>
        public static double[] SplineInterpolation(double[] srcX, double[] srcY, double[] interpX)
        {
            var count = srcX.Length;

            if (count <= 0 || srcY.Length != count)
            {
                throw new ArgumentException("the source arrays Xs and Ys must have the same length.");
            }

            point[] points = new point[count];
            for (var i = 0; i < count; i++)
            {
                points[i] = new point(srcX[i], srcY[i]);
            }

            point.DeSortX(points);
            if ((interpX.Min() < points.Min().x) || (interpX.Max() < points.Max().x))
            {
                throw new ArgumentException("the x range to be interpolated must be within the source x range.");
            }
            var y = splineInsertPoint(points, interpX);

            return(y);
        }