internal Tuple <double[], double[]> FunctionApproximationControlPointsAndAuxiliaryKnots(int degree, double[] pointsX, double[] pointsY, double[] knots, int[] knotsIndexes) { Tuple <double[][], double[]> matrixAndAuxKnots = FunctionApproximationMatrix(pointsX, knots, knotsIndexes, degree); double[][] matrix = matrixAndAuxKnots.Item1; double[][] transposeMatrix = MatrixOperations.TransposeMatrix(matrix); double[][] transposeAndMatrixMultiplicationInversion = MatrixOperations.MatrixInvert(MatrixOperations.MultiplyMatrices(transposeMatrix, matrix)); double[][] YMatrix = MatrixOperations.ArrayToMatrix(pointsY); double[][] finalMatrix; double[] finalMatrixAsArray; List <double[][]> matrixList = new List <double[][]>(); matrixList.Add(transposeAndMatrixMultiplicationInversion); matrixList.Add(transposeMatrix); matrixList.Add(YMatrix); finalMatrix = MatrixOperations.MultiplyListOfMatrices(matrixList); try { finalMatrixAsArray = MatrixOperations.OneColumnMatrixToArray(finalMatrix); } catch (NumberOfMatrixColumnIsNotOneException) { System.Diagnostics.Debug.WriteLine("Matrix cannot be converted to an array because number of columns is not one"); return(null); } return(new Tuple <double[], double[]>(finalMatrixAsArray, matrixAndAuxKnots.Item2)); }
internal Tuple <double[], double[]> FunctionControlPointsAndAuxiliaryKnots(int degree, double[] knots, double[] knotsFunctionValues, bool areKnotsService) { var matrixAndAuxKnots = FunctionBSplineMatrix(degree, knots, areKnotsService); var invertedMatrix = MatrixOperations.MatrixInvert(matrixAndAuxKnots.Item1); var knotsFunctionValuesMatrix = MatrixOperations.ArrayToMatrix(knotsFunctionValues); var controlPointsMatrix = MatrixOperations.MultiplyMatrices(invertedMatrix, knotsFunctionValuesMatrix); double[] controlPoints = null; try { controlPoints = MatrixOperations.OneColumnMatrixToArray(controlPointsMatrix); } catch (NumberOfMatrixColumnIsNotOneException) { System.Diagnostics.Debug.WriteLine("Matrix cannot be converted to an array because number of columns is not one"); return(null); } return(new Tuple <double[], double[]>(controlPoints, matrixAndAuxKnots.Item2)); }