improve identity

This commit is contained in:
2024-02-14 21:30:41 +01:00
parent a016163b86
commit cf64e4d33c
2 changed files with 10 additions and 5 deletions

View File

@@ -109,15 +109,18 @@ void Matrix::Transpose() {
} }
void Matrix::Identity() { void Matrix::Identity() {
assert(m_Lignes == m_Colonnes);
for (std::size_t i = 0; i < m_Lignes; i++) { for (std::size_t i = 0; i < m_Lignes; i++) {
for (std::size_t j = i; j < m_Colonnes; j++) { for (std::size_t j = i; j < m_Colonnes; j++) {
if (i != j) { at(i, j) = i == j;
at(i, j) = 0;
} else {
at(i, j) = 1;
} }
} }
} }
Matrix Matrix::Identity(std::size_t taille) {
Matrix id{taille, taille};
id.Identity();
return id;
} }
bool Matrix::IsInversed() const { bool Matrix::IsInversed() const {

View File

@@ -40,6 +40,8 @@ class Matrix {
void Identity(); void Identity();
static Matrix Identity(std::size_t taille);
bool IsInversed() const; bool IsInversed() const;
Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const; Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;