complex.h
#ifndef CMU462_COMPLEX_H
#define CMU462_COMPLEX_H
#include "CMU462.h"
#include "vector2D.h"
namespace CMU462 {
class Complex : public Vector2D {
public:
Complex( ) : Vector2D( 0.0, 0.0 ) { }
Complex( double a, double b ) : Vector2D( a, b ) { }
Complex( const Vector2D& v ) : Vector2D( v ) { }
inline Complex conj( ) const {
return Complex( x, -y );
}
inline Complex inv( ) const {
double r = 1.0/norm2();
return Complex( r*x, -r*y );
}
inline double arg( ) const {
return atan2( y, x );
}
inline Complex exponential( ) const {
return exp( x ) * Complex( cos( y ), sin( y ));
}
// Complex multiply by z
inline void operator*=( const Complex& z ) {
double a = x;
double b = y;
double c = z.x;
double d = z.y;
x = a*c-b*d;
y = a*d+b*c;
}
// complex divide by z
void operator/=( const Complex& z ) {
*this *= z.inv();
}
}; // class Complex
// returns the real part of z
double Re( const Complex& z );
// returns the imaginary part of z
double Im( const Complex& z );
// binary Complex multiplication
inline Complex operator*( const Complex& z1, const Complex& z2 ) {
Complex z = z1;
z *= z2;
return z;
}
// complex division
inline Complex operator/( const Complex& z1, const Complex& z2 ) {
Complex z = z1;
z /= z2;
return z;
}
// prints components
std::ostream& operator<<( std::ostream& os, const Complex& z );
} // namespace CMU462
#endif // CMU462_COMPLEX_H
CMU462::Complex::Complex
Complex(const Vector2D &v)
Constructor.
Definition: complex.h:32
CMU462::Vector2D::norm2
double norm2(void) const
Returns norm squared.
Definition: vector2D.h:105
CMU462::Complex::arg
double arg() const
Return argument.
Definition: complex.h:52
CMU462::Complex
Represents complex numbers as 2D vectors of their real and imaginary components.
Definition: complex.h:13
CMU462
Definition: CMU462.h:8
CMU462::Vector2D
Defines 2D vectors.
Definition: vector2D.h:14
CMU462::Complex::Complex
Complex()
Constructor.
Definition: complex.h:20
CMU462::Complex::Complex
Complex(double a, double b)
Constructor.
Definition: complex.h:26
CMU462::Complex::conj
Complex conj() const
Compute the complex conjugate.
Definition: complex.h:37
CMU462::Complex::inv
Complex inv() const
Compute the inverse.
Definition: complex.h:44
CMU462::Complex::exponential
Complex exponential() const
Complex exponentiation.
Definition: complex.h:59