Exemple #1
0
        public EdMatrix getInverse()
        {
            EdMatrix matforinv = new EdMatrix();

            matforinv.matrix = matrix;

            /*matforinv.matrix[0, 0] = 1;
            *  matforinv.matrix[1, 0] = 2;
            *  matforinv.matrix[2, 0] = 3;
            *  matforinv.matrix[0, 1] = 0;
            *  matforinv.matrix[1, 1] = 1;
            *  matforinv.matrix[2, 1] = 4;
            *  matforinv.matrix[0, 2] = 5;
            *  matforinv.matrix[1, 2] = 6;
            *  matforinv.matrix[2, 2] = 0;*/
            double   detWhole  = determinant(matforinv.matrix);
            EdMatrix transpose = new EdMatrix();
            EdMatrix adjunct   = new EdMatrix();
            EdMatrix inverse   = new EdMatrix();

            if (detWhole != 0)
            {
                transpose.matrix[0, 0] = matforinv.matrix[0, 0];
                transpose.matrix[1, 1] = matforinv.matrix[1, 1];
                transpose.matrix[2, 2] = matforinv.matrix[2, 2];

                transpose.matrix[0, 1] = matforinv.matrix[1, 0];
                transpose.matrix[0, 2] = matforinv.matrix[2, 0];
                transpose.matrix[1, 0] = matforinv.matrix[0, 1];
                transpose.matrix[1, 2] = matforinv.matrix[2, 1];
                transpose.matrix[2, 0] = matforinv.matrix[0, 2];
                transpose.matrix[2, 1] = matforinv.matrix[1, 2];

                int factor = 1;

                for (int i = 0; i < 3; ++i)
                {
                    for (int j = 0; j < 3; ++j)
                    {
                        double thisValue = transpose.matrix[i, j];
                        double[,] reduced = reduceMatrix(transpose.matrix, i, j);
                        double detReduced = transpose.determinant(reduced);
                        adjunct.matrix[i, j] = detReduced * factor;
                        inverse.matrix[i, j] = detReduced * factor / detWhole;
                        factor *= -1;
                    }
                }
                return(inverse);
            }
            else
            {
                return(new EdMatrix()); //empty
            }
        }
Exemple #2
0
        /*
         * The following functionaility is based on the code in the python library
         * https://pdb-eda.readthedocs.io/en/latest/
         *
         */

        private void calculateOrthoMat()
        {
            _orthoMat = new EdMatrix();
            double alpha = Math.PI / 180 * w14_CELLB_X;
            double beta  = Math.PI / 180 * w15_CELLB_Y;
            double gamma = Math.PI / 180 * w16_CELLB_Z;
            double temp  = Math.Sqrt(1 - Math.Pow(Math.Cos(alpha), 2) - Math.Pow(Math.Cos(beta), 2) - Math.Pow(Math.Cos(gamma), 2) + 2 * Math.Cos(alpha) * Math.Cos(beta) * Math.Cos(gamma));

            _orthoMat.matrix[0, 0] = w11_CELLA_X;
            _orthoMat.matrix[0, 1] = w12_CELLA_Y * Math.Cos(gamma);
            _orthoMat.matrix[0, 2] = w13_CELLA_Z * Math.Cos(beta);
            _orthoMat.matrix[1, 0] = 0;
            _orthoMat.matrix[1, 1] = w12_CELLA_Y * Math.Sin(gamma);
            _orthoMat.matrix[1, 2] = w13_CELLA_Z * (Math.Cos(alpha) - Math.Cos(beta) * Math.Cos(gamma)) / Math.Sin(gamma);
            _orthoMat.matrix[2, 0] = 0;
            _orthoMat.matrix[2, 1] = 0;
            _orthoMat.matrix[2, 2] = w13_CELLA_Z * temp / Math.Sin(gamma);

            _deOrthoMat = _orthoMat.getInverse();
        }