From caf83ef7ca3e2725a25df9da0f75035a0c05d028 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Tue, 12 Mar 2024 21:24:24 -0400 Subject: [PATCH] jacobienne --- labo01/Matrix.h | 22 ++++++++++++++++++++++ labo_physique/ParticleSystem.cpp | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/labo01/Matrix.h b/labo01/Matrix.h index d285e6d..a725e3a 100644 --- a/labo01/Matrix.h +++ b/labo01/Matrix.h @@ -318,6 +318,28 @@ namespace gti320 { return *this; } + /** + * Opérateur de d'addition d'une autre matrice + * + * Ajoute toutes les entrées de la matrice dans la sous-matrice. + * + * Note : la taille de la matrice doit correspondre à la taille de la + * sous-matrice. + */ + template + SubMatrix &operator+=(const Matrix<_OtherScalar, _OtherRows, _OtherCols, _OtherStorage> &matrix) { + assert(this->rows() == matrix.rows()); + assert(this->cols() == matrix.cols()); + + for (int col = 0; col < this->cols(); col++) { + for (int row = 0; row < this->rows(); row++) { + (*this)(row, col) = (*this)(row, col) + matrix(row, col); + } + } + + return *this; + } + /** * Accesseur aux entrées de la sous-matrice (lecture seule) * diff --git a/labo_physique/ParticleSystem.cpp b/labo_physique/ParticleSystem.cpp index 178f08b..a325c98 100644 --- a/labo_physique/ParticleSystem.cpp +++ b/labo_physique/ParticleSystem.cpp @@ -145,9 +145,9 @@ void ParticleSystem::buildDfDx(Matrix &dfdx) { Matrix ndiag = -1.0f * diag; - dfdx.block(spring.index0, spring.index1, 2, 2) = diag; - dfdx.block(spring.index0 + 2, spring.index1 + 2, 2, 2) = diag; - dfdx.block(spring.index0 + 2, spring.index1, 2, 2) = ndiag; - dfdx.block(spring.index0, spring.index1 + 2, 2, 2) = ndiag; + dfdx.block(spring.index0, spring.index1, 2, 2) += diag; + dfdx.block(spring.index0 + 2, spring.index1 + 2, 2, 2) += diag; + dfdx.block(spring.index0 + 2, spring.index1, 2, 2) += ndiag; + dfdx.block(spring.index0, spring.index1 + 2, 2, 2) += ndiag; } }