|
|
|
|
@ -19,29 +19,30 @@
|
|
|
|
|
* @brief Function Magnum::Math::Algorithms::gramSchmidtInPlace(), Magnum::Math::Algorithms::gramSchmidt() |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "Math/Matrix.h" |
|
|
|
|
#include "Math/RectangularMatrix.h" |
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Math { namespace Algorithms { |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@brief Gram-schmidt matrix orthonormalization |
|
|
|
|
@brief Gram-Schmidt matrix orthonormalization |
|
|
|
|
@param[in,out] matrix Matrix to perform orthonormalization on |
|
|
|
|
*/ |
|
|
|
|
template<std::size_t size, class T> void gramSchmidtInPlace(Matrix<size, T>& matrix) { |
|
|
|
|
for(std::size_t i = 0; i != size; ++i) { |
|
|
|
|
template<std::size_t cols, std::size_t rows, class T> void gramSchmidtInPlace(RectangularMatrix<cols, rows, T>& matrix) { |
|
|
|
|
static_assert(cols <= rows, "Unsupported matrix aspect ratio"); |
|
|
|
|
for(std::size_t i = 0; i != cols; ++i) { |
|
|
|
|
matrix[i] = matrix[i].normalized(); |
|
|
|
|
for(std::size_t j = i+1; j != size; ++j) |
|
|
|
|
for(std::size_t j = i+1; j != cols; ++j) |
|
|
|
|
matrix[j] -= matrix[j].projected(matrix[i]); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@brief Gram-schmidt matrix orthonormalization |
|
|
|
|
@brief Gram-Schmidt matrix orthonormalization |
|
|
|
|
|
|
|
|
|
Unlike gramSchmidtInPlace() returns the modified matrix instead of performing |
|
|
|
|
the orthonormalization in-place. |
|
|
|
|
*/ |
|
|
|
|
template<std::size_t size, class T> Matrix<size, T> gramSchmidt(Matrix<size, T> matrix) { |
|
|
|
|
template<std::size_t cols, std::size_t rows, class T> RectangularMatrix<cols, rows, T> gramSchmidt(RectangularMatrix<cols, rows, T> matrix) { |
|
|
|
|
gramSchmidtInPlace(matrix); |
|
|
|
|
return matrix; |
|
|
|
|
} |
|
|
|
|
|