Browse Source

Math: converting complex number to rotation matrix.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
8aade86571
  1. 21
      src/Math/Complex.h
  2. 13
      src/Math/Test/ComplexTest.cpp

21
src/Math/Complex.h

@ -23,10 +23,7 @@
#include <Utility/Assert.h>
#include <Utility/Debug.h>
#include "Math/Angle.h"
#include "Math/MathTypeTraits.h"
#include "magnumVisibility.h"
#include "Math/Matrix.h"
namespace Magnum { namespace Math {
@ -125,6 +122,22 @@ template<class T> class Complex {
return Rad<T>(std::atan2(_imaginary, _real));
}
/**
* @brief Convert complex number to rotation matrix
*
* @f[
* M = \begin{pmatrix}
* a & -b \\
* b & a
* \end{pmatrix}
* @f]
* @see Matrix3::from(const Matrix<2, T>&, const Vector2<T>&)
*/
Matrix<2, T> matrix() const {
return {Vector<2, T>(_real, _imaginary),
Vector<2, T>(-_imaginary, _real)};
}
/**
* @brief Add complex number and assign
*

13
src/Math/Test/ComplexTest.cpp

@ -17,7 +17,7 @@
#include <TestSuite/Tester.h>
#include "Math/Complex.h"
#include "Math/Vector2.h"
#include "Math/Matrix3.h"
namespace Magnum { namespace Math { namespace Test {
@ -47,6 +47,7 @@ class ComplexTest: public Corrade::TestSuite::Tester {
void angle();
void rotation();
void matrix();
void debug();
};
@ -74,6 +75,7 @@ ComplexTest::ComplexTest() {
&ComplexTest::angle,
&ComplexTest::rotation,
&ComplexTest::matrix,
&ComplexTest::debug);
}
@ -82,6 +84,8 @@ typedef Math::Deg<float> Deg;
typedef Math::Rad<float> Rad;
typedef Math::Complex<float> Complex;
typedef Math::Vector2<float> Vector2;
typedef Math::Matrix3<float> Matrix3;
typedef Math::Matrix<2, float> Matrix2;
void ComplexTest::construct() {
Complex c(0.5f, -3.7f);
@ -245,6 +249,13 @@ void ComplexTest::rotation() {
CORRADE_COMPARE_AS(Complex().rotationAngle(), Deg(0.0f), Rad);
}
void ComplexTest::matrix() {
Complex a = Complex::rotation(Deg(37.0f));
Matrix2 m = Matrix3::rotation(Deg(37.0f)).rotationScaling();
CORRADE_COMPARE(a.matrix(), m);
}
void ComplexTest::debug() {
std::ostringstream o;

Loading…
Cancel
Save