/// <summary> /// Interpolates between x and y points /// </summary> /// <param name="x">X coordinate of points</param> /// <param name="y">Y coordinate of points </param> /// <param name="xs">X coordinats of output. has to have output length</param> /// <returns>a double array with Y coordinates</returns> public static double[] Do(double[] x, double[] y, double[] xs) { if (x == null || y == null || xs == null) { throw new ArgumentNullException(); } if (xs.Length <= x.Length) { throw new ArgumentException("xs has to be longer than x/y"); } CubicSpline Spline = new CubicSpline(); return Spline.FitAndEval(x, y, xs); }
/// <summary> /// Interpolates between x and y points /// </summary> /// <param name="x">X coordinate of points</param> /// <param name="y">Y coordinate of points </param> /// <param name="length">length of output point array</param> /// <returns>a point array with interpolated points</returns> public static double[] Do(double[] x, double[] y, int length) { if (x == null || y == null) { throw new ArgumentNullException(); } CubicSpline Spline = new CubicSpline(); //PointD[] Output = new PointD[length]; double[] xs = new double[length]; //double[] ys; double d = Math.Abs(x[0] - x[x.Length - 1]); for (int i = 0; i < length; i++) { xs[i] = i * d / (double)(length - 1); } return Spline.FitAndEval(x, y, xs); //for (int i = 0; i < length; i++) { Output[i] = new PointD((float)xs[i], (float)ys[i]); } //return Output; }
/// <summary> /// Interpolates between a set of points /// </summary> /// <param name="points">a set of points to interpolate</param> /// <param name="length">length of output point array</param> /// <returns>a point array with interpolated points</returns> public static PointD[] Do(PointD[] points, int length) { if (points == null) { throw new ArgumentNullException(); } CubicSpline Spline = new CubicSpline(); PointD[] Output = new PointD[length]; double[] xs = new double[length]; double[] x = new double[points.Length]; double[] y = new double[points.Length]; double[] ys; double d = Math.Abs(points[0].X - points[points.Length - 1].X); for (int i = 0; i < length; i++) { xs[i] = i * d / (double)(length - 1); } for (int i = 0; i < points.Length; i++) { x[i] = points[i].X; y[i] = points[i].Y; } ys = Spline.FitAndEval(x, y, xs); for (int i = 0; i < length; i++) { Output[i] = new PointD((float)xs[i], (float)ys[i]); } return Output; }