From 1967179a40cdca5ec23ec531876c46530b26610f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Wed, 6 Feb 2013 11:29:28 +0100 Subject: [PATCH] Math: slight improvement of Gram-Schmidt orthonormalization algorithm. Using Vector::projectOntoNormalized(), as it is slightly faster, renamed the functions to properly mention that this is orthonormalization. --- src/Math/Algorithms/GramSchmidt.h | 16 ++++++++-------- src/Math/Algorithms/Test/GramSchmidtTest.cpp | 8 ++++---- src/SceneGraph/EuclideanMatrixTransformation2D.h | 2 +- src/SceneGraph/EuclideanMatrixTransformation3D.h | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Math/Algorithms/GramSchmidt.h b/src/Math/Algorithms/GramSchmidt.h index c6f60e2f5..905641766 100644 --- a/src/Math/Algorithms/GramSchmidt.h +++ b/src/Math/Algorithms/GramSchmidt.h @@ -16,7 +16,7 @@ */ /** @file - * @brief Function Magnum::Math::Algorithms::gramSchmidtInPlace(), Magnum::Math::Algorithms::gramSchmidt() + * @brief Function Magnum::Math::Algorithms::gramSchmidtOrthonormalizeInPlace(), Magnum::Math::Algorithms::gramSchmidtOrthonormalize() */ #include "Math/RectangularMatrix.h" @@ -24,26 +24,26 @@ namespace Magnum { namespace Math { namespace Algorithms { /** -@brief Gram-Schmidt matrix orthonormalization +@brief In-place Gram-Schmidt matrix orthonormalization @param[in,out] matrix Matrix to perform orthonormalization on */ -template void gramSchmidtInPlace(RectangularMatrix& matrix) { +template void gramSchmidtOrthonormalizeInPlace(RectangularMatrix& 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 != cols; ++j) - matrix[j] -= matrix[j].projected(matrix[i]); + matrix[j] -= matrix[j].projectedOntoNormalized(matrix[i]); } } /** @brief Gram-Schmidt matrix orthonormalization -Unlike gramSchmidtInPlace() returns the modified matrix instead of performing -the orthonormalization in-place. +Unlike gramSchmidtOrthonormalizeInPlace() returns the modified matrix instead +of performing the orthonormalization in-place. */ -template RectangularMatrix gramSchmidt(RectangularMatrix matrix) { - gramSchmidtInPlace(matrix); +template RectangularMatrix gramSchmidtOrthonormalize(RectangularMatrix matrix) { + gramSchmidtOrthonormalizeInPlace(matrix); return matrix; } diff --git a/src/Math/Algorithms/Test/GramSchmidtTest.cpp b/src/Math/Algorithms/Test/GramSchmidtTest.cpp index 3313c3ac8..85700deaa 100644 --- a/src/Math/Algorithms/Test/GramSchmidtTest.cpp +++ b/src/Math/Algorithms/Test/GramSchmidtTest.cpp @@ -23,22 +23,22 @@ class GramSchmidtTest: public Corrade::TestSuite::Tester { public: GramSchmidtTest(); - void test(); + void orthonormalize(); }; typedef RectangularMatrix<3, 3, float> Matrix3; typedef Vector<3, float> Vector3; GramSchmidtTest::GramSchmidtTest() { - addTests(&GramSchmidtTest::test); + addTests(&GramSchmidtTest::orthonormalize); } -void GramSchmidtTest::test() { +void GramSchmidtTest::orthonormalize() { Matrix3 m(Vector3(3.0f, 5.0f, 8.0f), Vector3(4.0f, 4.0f, 7.0f), Vector3(7.0f, -1.0f, 8.0f)); - Matrix3 normalized = Algorithms::gramSchmidt(m); + Matrix3 normalized = Algorithms::gramSchmidtOrthonormalize(m); /* Verify the first vector is in direction of first original */ CORRADE_COMPARE(normalized[0], m[0].normalized()); diff --git a/src/SceneGraph/EuclideanMatrixTransformation2D.h b/src/SceneGraph/EuclideanMatrixTransformation2D.h index cb4a59081..fa80ed2a6 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation2D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation2D.h @@ -85,7 +85,7 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D { */ EuclideanMatrixTransformation2D* normalizeRotation() { setTransformation(Math::Matrix3::from( - Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); return this; } diff --git a/src/SceneGraph/EuclideanMatrixTransformation3D.h b/src/SceneGraph/EuclideanMatrixTransformation3D.h index d39dac91a..693b2b6c1 100644 --- a/src/SceneGraph/EuclideanMatrixTransformation3D.h +++ b/src/SceneGraph/EuclideanMatrixTransformation3D.h @@ -85,7 +85,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D { */ EuclideanMatrixTransformation3D* normalizeRotation() { setTransformation(Math::Matrix4::from( - Math::Algorithms::gramSchmidt(_transformation.rotationScaling()), + Math::Algorithms::gramSchmidtOrthonormalize(_transformation.rotationScaling()), _transformation.translation())); return this; }