mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
added inverse method
This commit is contained in:
@@ -359,6 +359,25 @@ namespace omath
|
||||
};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::optional<Mat> Inverted() const
|
||||
{
|
||||
const auto det = Determinant();
|
||||
|
||||
if (det == 0)
|
||||
return std::nullopt;
|
||||
|
||||
const auto transposed = Transposed();
|
||||
Mat result;
|
||||
|
||||
for (std::size_t row = 0; row < Rows; row++)
|
||||
for (std::size_t column = 0; column < Rows; column++)
|
||||
result.At(row, column) = transposed.AlgComplement(row, column);
|
||||
|
||||
result /= det;
|
||||
|
||||
return {result};
|
||||
}
|
||||
private:
|
||||
std::array<Type, Rows * Columns> m_data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user