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 = MathOperations.TransposeMatrix(matrix);
            double[][]        transposeAndMatrixMultiplicationInversion = MathOperations.MatrixInvert(MathOperations.MultiplyMatrices(transposeMatrix, matrix));
            double[][]        YMatrix = ArrayMyUtils.ArrayToMatrix(pointsY);
            double[][]        finalMatrix;
            double[]          finalMatrixAsArray;
            List <double[][]> matrixList = new List <double[][]>();

            matrixList.Add(transposeAndMatrixMultiplicationInversion);
            matrixList.Add(transposeMatrix);
            matrixList.Add(YMatrix);
            finalMatrix = MathOperations.MultiplyListOfMatrices(matrixList);
            try
            {
                finalMatrixAsArray = ArrayMyUtils.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));
        }
Example #2
0
        internal Tuple <double[], double[]> GlobalControlPointsAndAuxiliaryKnots(int degree, double[] knots, double[] knotsFunctionValues, double leftDerivation, double rightDerivation, bool areKnotsService)
        {
            var matrixAndAuxKnots = GlobalBSplineMatrix(degree, knots, areKnotsService);
            var invertedMatrix    = MathOperations.MatrixInvert(matrixAndAuxKnots.Item1);
            var controlPoints     = MathOperations.MultiplyMatrixAndVector(invertedMatrix, knotsFunctionValues, leftDerivation, rightDerivation);


            //var knotsFunctionValuesMatrix = ArrayMyUtils.ArrayToMatrix(knotsFunctionValues);
            //var controlPointsMatrix = AlgebraOperations.MultiplyMatrices(invertedMatrix,knotsFunctionValuesMatrix);
            //double[] controlPoints = null;
            //try
            //{
            //    controlPoints = ArrayMyUtils.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));
        }