Browse Source

Math: "dot product" of Complex is real number.

Brain failure #2. Also I don't know if such thing as dot product exists
here :-)
pull/278/head
Vladimír Vondruš 13 years ago
parent
commit
c847e1551f
  1. 14
      src/Math/Complex.h
  2. 2
      src/Math/Test/ComplexTest.cpp

14
src/Math/Complex.h

@ -43,12 +43,12 @@ template<class T> class Complex {
* @brief Dot product
*
* @f[
* c_0 \cdot c_1 = c_0 \overline{c_1} = (a_0 a_1 + b_0 b_1) + i(a_1 b_0 - a_0 b_1)
* c_0 \cdot c_1 = a_0 a_1 + b_0 b_1
* @f]
* @see dot() const
*/
inline static Complex<T> dot(const Complex<T>& a, const Complex<T>& b) {
return a*b.conjugated();
inline static T dot(const Complex<T>& a, const Complex<T>& b) {
return a._real*b._real + a._imaginary*b._imaginary;
}
/**
@ -277,12 +277,12 @@ template<class T> class Complex {
*
* Should be used instead of length() for comparing complex number length
* with other values, because it doesn't compute the square root. @f[
* c \cdot c = c \overline c = a^2 + b^2
* c \cdot c = a^2 + b^2
* @f]
* @see dot(const Complex&, const Complex&)
*/
inline T dot() const {
return _real*_real + _imaginary*_imaginary;
return dot(*this, *this);
}
/**
@ -290,7 +290,7 @@ template<class T> class Complex {
*
* See also dot() const which is faster for comparing length with other
* values. @f[
* |c| = \sqrt{c \overline c} = \sqrt{a^2 + b^2}
* |c| = \sqrt{c \cdot c}
* @f]
*/
inline T length() const {
@ -318,7 +318,7 @@ template<class T> class Complex {
*
* See invertedNormalized() which is faster for normalized
* complex numbers. @f[
* c^{-1} = \frac{\overline c}{c \overline c} = \frac{\overline c}{a^2 + b^2}
* c^{-1} = \frac{\overline c}{|c|^2} = \frac{\overline c}{c \cdot c}
* @f]
*/
inline Complex<T> inverted() const {

2
src/Math/Test/ComplexTest.cpp

@ -183,7 +183,7 @@ void ComplexTest::dot() {
Complex a(5.0f, 3.0f);
Complex b(6.0f, -7.0f);
CORRADE_COMPARE(Complex::dot(a, b), Complex(9.0f, 53.0f));
CORRADE_COMPARE(Complex::dot(a, b), 9.0f);
}
void ComplexTest::dotSelf() {

Loading…
Cancel
Save