private static List <System.Windows.Point> Spline(List <System.Windows.Point> point_vector, int splits) { List <System.Windows.Point> temp1 = new List <System.Windows.Point>(); General.Vector Y = new General.Vector(point_vector.Count); General.Vector a = new General.Vector(point_vector.Count); General.Matrix A = new General.Matrix(point_vector.Count); double[] x = new double[splits]; double[] y = new double[splits]; for (int i = 0; i < point_vector.Count; i++) { double temp = point_vector[i].X; y[i] = point_vector[i].Y; for (int j = 0; j < point_vector.Count; j++) { A[i, j] = System.Math.Pow(temp, j); } } a = A.InverceMatrix() * Y; for (int k = 0; k < splits; k++) { var max = (search_max(point_vector, XorY.X) - search_min(point_vector, XorY.X)); x[k] = max * k / splits; } for (int k = 0; k < splits; k++) { for (int i = 0; i < point_vector.Count; i++) { y[k] += a[i] * System.Math.Pow(x[k], i); } } for (int k = 0; k < splits; ++k) { System.Windows.Point temp = new System.Windows.Point(x[k], y[k]); temp1.Add(temp); } return(temp1); }
public static List <System.Windows.Point> SplineInterpolation(List <System.Windows.Point> point_vector, int _splits) { int n = point_vector.Count - 1; var splits = _splits / n; double[] ax = new double[n + 1]; double[] bx = new double[n + 1]; double[] cx = new double[n + 1]; double[] dx = new double[n + 1]; double[] ay = new double[n + 1]; double[] by = new double[n + 1]; double[] cy = new double[n + 1]; double[] dy = new double[n + 1]; double[] u = new double[splits]; General.Matrix A = new General.Matrix(n + 1); General.Vector vec_bx = new General.Vector(n + 1); General.Vector vec_cx = new General.Vector(n + 1); General.Vector vec_by = new General.Vector(n + 1); General.Vector vec_cy = new General.Vector(n + 1); List <System.Windows.Point> new_list = new List <System.Windows.Point>(); for (int i = 0; i < n + 1; i++) { ax[i] = point_vector[i].X; ay[i] = point_vector[i].Y; } A[0, 0] = 1; A[n, n] = 1; for (int i = 1; i < n; i++) { A[i, i - 1] = 1; A[i, i] = 4; A[i, i + 1] = 1; } vec_bx[0] = 0; vec_bx[n] = 0; vec_by[0] = 0; vec_by[n] = 0; for (int i = 1; i < n; i++) { vec_bx[i] = 3 * (ax[i + 1] - 2 * ax[i] + ax[i - 1]); vec_by[i] = 3 * (ay[i + 1] - 2 * ay[i] + ay[i - 1]); } //cx = (A.InverceMatrix() * vec_bx).ToDoubleArray(); //cy = (A.InverceMatrix() * vec_by).ToDoubleArray(); General.Solvers.JacobiMethod jSolver1 = new Solvers.JacobiMethod(A.GetArray(), vec_bx.ToDoubleArray()); General.Solvers.JacobiMethod jSolver2 = new Solvers.JacobiMethod(A.GetArray(), vec_by.ToDoubleArray()); jSolver1.Error = 1E-15; jSolver2.Error = 1E-15; jSolver1.CheckInterval = 10; jSolver2.CheckInterval = 10; jSolver1.Solve(); jSolver2.Solve(); cx = jSolver1.Solution; cy = jSolver2.Solution; for (int i = 0; i < n; i++) { bx[i] = (ax[i + 1] - ax[i]) - (cx[i + 1] + 2 * cx[i]) / 3; dx[i] = (cx[i + 1] - cx[i]) / 3; by[i] = (ay[i + 1] - ay[i]) - (cy[i + 1] + 2 * cy[i]) / 3; dy[i] = (cy[i + 1] - cy[i]) / 3; } //Generate x point for (int k = 0; k < splits; k++) { u[k] = (double)k / (double)splits; } for (int i = 0; i < n; i++) { for (int k = 0; k < splits; k++) { var x = ax[i] + bx[i] * u[k] + cx[i] * System.Math.Pow(u[k], 2) + dx[i] * System.Math.Pow(u[k], 3); var y = ay[i] + by[i] * u[k] + cy[i] * System.Math.Pow(u[k], 2) + dy[i] * System.Math.Pow(u[k], 3); new_list.Add(new System.Windows.Point(x, y)); } } new_list.Add(point_vector[n]); return(new_list); }