Browse Source

Math: inversion of DualComplex.

pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
fbac6662fa
  1. 27
      src/Math/DualComplex.h
  2. 1
      src/Math/Test/CMakeLists.txt
  3. 28
      src/Math/Test/DualComplexTest.cpp

27
src/Math/DualComplex.h

@ -124,6 +124,33 @@ template<class T> class DualComplex: public Dual<Complex<T>> {
return (*this)/length(); return (*this)/length();
} }
/**
* @brief Inverted dual complex number
*
* See invertedNormalized() which is faster for normalized dual complex
* numbers. @f[
* \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2}
* @f]
*/
inline DualComplex<T> inverted() const {
return complexConjugated()/lengthSquared();
}
/**
* @brief Inverted normalized dual complex number
*
* Equivalent to complexConjugated(). Expects that the complex number
* is normalized. @f[
* \hat c^{-1} = \frac{\hat c^*}{|\hat c|^2} = \hat c^*
* @f]
* @see inverted()
*/
inline DualComplex<T> invertedNormalized() const {
CORRADE_ASSERT(lengthSquared() == Dual<T>(1),
"Math::DualComplex::invertedNormalized(): dual complex number must be normalized", {});
return complexConjugated();
}
MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex) MAGNUM_DUAL_SUBCLASS_IMPLEMENTATION(DualComplex, Complex)
private: private:

1
src/Math/Test/CMakeLists.txt

@ -28,6 +28,7 @@ set_target_properties(
MathMatrix3Test MathMatrix3Test
MathMatrix4Test MathMatrix4Test
MathComplexTest MathComplexTest
MathDualComplexTest
MathQuaternionTest MathQuaternionTest
MathDualQuaternionTest MathDualQuaternionTest
PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)

28
src/Math/Test/DualComplexTest.cpp

@ -36,6 +36,8 @@ class DualComplexTest: public Corrade::TestSuite::Tester {
void complexConjugated(); void complexConjugated();
void dualConjugated(); void dualConjugated();
void conjugated(); void conjugated();
void inverted();
void invertedNormalized();
void debug(); void debug();
}; };
@ -57,6 +59,8 @@ DualComplexTest::DualComplexTest() {
&DualComplexTest::complexConjugated, &DualComplexTest::complexConjugated,
&DualComplexTest::dualConjugated, &DualComplexTest::dualConjugated,
&DualComplexTest::conjugated, &DualComplexTest::conjugated,
&DualComplexTest::inverted,
&DualComplexTest::invertedNormalized,
&DualComplexTest::debug); &DualComplexTest::debug);
} }
@ -121,6 +125,30 @@ void DualComplexTest::conjugated() {
CORRADE_COMPARE(a.conjugated(), b); CORRADE_COMPARE(a.conjugated(), b);
} }
void DualComplexTest::inverted() {
DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f});
DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f});
CORRADE_COMPARE(a*a.inverted(), DualComplex());
CORRADE_COMPARE(a.inverted(), b/Dual(7.25f, -43.5f));
}
void DualComplexTest::invertedNormalized() {
DualComplex a({-1.0f, 2.5f}, { 3.0f, -7.5f});
DualComplex b({-1.0f, -2.5f}, { 3.0f, 7.5f});
std::ostringstream o;
Error::setOutput(&o);
CORRADE_COMPARE(a.invertedNormalized(), DualComplex());
CORRADE_COMPARE(o.str(), "Math::DualComplex::invertedNormalized(): dual complex number must be normalized\n");
DualComplex normalized = a.normalized();
DualComplex inverted = normalized.invertedNormalized();
CORRADE_COMPARE(normalized*inverted, DualComplex());
CORRADE_COMPARE(inverted*normalized, DualComplex());
CORRADE_COMPARE(inverted, b/Math::sqrt(Dual(7.25f, -43.5f)));
}
void DualComplexTest::debug() { void DualComplexTest::debug() {
std::ostringstream o; std::ostringstream o;

Loading…
Cancel
Save