Bariskas / oop

Лабораторные по ООП 2 курс ИПС
0 stars 0 forks source link

Замечания по InvertMatrix #3

Open alexey-malov opened 7 years ago

alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
void GetMatrixFromStream(ifstream& matrixFileStream, double(&sourceMatrix)[3][3]);
void GetInvertMatrix(double(&sourceMatrix)[3][3], double(&invertMatrix)[3][3]);
void GetMinorMatrix(double(&sourceMatrix)[3][3], double(&minorMatrix)[3][3]);
void TransposeMatrix(double(&matrixToTranspose)[3][3]);
void InvertMatrix(double(&matrixToInvert)[3][3], double determinant);
void WriteMatrixToConsole(double(&matrix)[3][3]);
typedef double matrix[3][3];
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
void InvertMatrix(double(&matrixToTranspose)[3][3], double determinant)
{
    double revertDeterminant = 1 / determinant;
    for (int i = 0; i < 3; ++i)
    {
        for (int j = 0; j < 3; ++j)
        {
            matrixToTranspose[i][j] *= revertDeterminant;
        }
    }
}
alexey-malov commented 7 years ago
alexey-malov commented 7 years ago
bool IsOnlyDigitString(const std::string &str)
{
    return all_of(str.begin(), str.end(), [](char i) { return isdigit(i) || i == '-' || i == '.'; });
}
alexey-malov commented 7 years ago
    if (abs(determinant) <= DBL_EPSILON) // сравнение с нулем
    {
        return false;
    }

    if (abs(x - y) <= DBL_EPSILON) // сравнение с другим числом
    {
        return false;
    }
alexey-malov commented 7 years ago
    double (& sm)[3][3] = sourceMatrix;
    double determinant = (sm[0][0] * sm[1][1] * sm[2][2]) + (sm[0][1] * sm[1][2] * sm[2][0]) + (sm[0][2] * sm[1][0] * sm[2][1]) - 
        (sm[0][2] * sm[1][1] * sm[2][0]) - (sm[0][0] * sm[2][1] * sm[1][2]) - (sm[1][0] * sm[0][1] * sm[2][2]);