diff --git a/src/Math/Complex.h b/src/Math/Complex.h index 528ec3c12..b88d8e4d0 100644 --- a/src/Math/Complex.h +++ b/src/Math/Complex.h @@ -155,7 +155,7 @@ template class Complex { * b & a * \end{pmatrix} * @f] - * @see Matrix3::from(const Matrix<2, T>&, const Vector2&) + * @see DualComplex::matrix(), Matrix3::from(const Matrix<2, T>&, const Vector2&) */ Matrix<2, T> matrix() const { return {Vector<2, T>(_real, _imaginary), diff --git a/src/Math/DualComplex.h b/src/Math/DualComplex.h index c150f378d..d4484727a 100644 --- a/src/Math/DualComplex.h +++ b/src/Math/DualComplex.h @@ -21,6 +21,7 @@ #include "Math/Dual.h" #include "Math/Complex.h" +#include "Math/Matrix3.h" namespace Magnum { namespace Math { @@ -126,6 +127,15 @@ template class DualComplex: public Dual> { return Vector2(this->dual()); } + /** + * @brief Convert dual complex number to transformation matrix + * + * @see Complex::matrix() + */ + inline Matrix3 matrix() const { + return Matrix3::from(this->real().matrix(), translation()); + } + /** * @brief Multipy with dual complex number * diff --git a/src/Math/Test/DualComplexTest.cpp b/src/Math/Test/DualComplexTest.cpp index 4922e4ecb..acc5bd03e 100644 --- a/src/Math/Test/DualComplexTest.cpp +++ b/src/Math/Test/DualComplexTest.cpp @@ -46,6 +46,7 @@ class DualComplexTest: public Corrade::TestSuite::Tester { void rotation(); void translation(); void combinedTransformParts(); + void matrix(); void debug(); }; @@ -55,6 +56,7 @@ typedef Math::Rad Rad; typedef Math::Complex Complex; typedef Math::Dual Dual; typedef Math::DualComplex DualComplex; +typedef Math::Matrix3 Matrix3; typedef Math::Vector2 Vector2; DualComplexTest::DualComplexTest() { @@ -79,6 +81,7 @@ DualComplexTest::DualComplexTest() { &DualComplexTest::rotation, &DualComplexTest::translation, &DualComplexTest::combinedTransformParts, + &DualComplexTest::matrix, &DualComplexTest::debug); } @@ -206,6 +209,13 @@ void DualComplexTest::combinedTransformParts() { CORRADE_COMPARE(b.translation(), Complex::rotation(Deg(23.0f)).transformVector(translation)); } +void DualComplexTest::matrix() { + DualComplex a = DualComplex::rotation(Deg(23.0f))*DualComplex::translation({2.0f, 3.0f}); + Matrix3 m = Matrix3::rotation(Deg(23.0f))*Matrix3::translation({2.0f, 3.0f}); + + CORRADE_COMPARE(a.matrix(), m); +} + void DualComplexTest::debug() { std::ostringstream o;