using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrasformataDiFourier
{
public class Complex
{
public double real = 0.0;
public double imag = 0.0;
//Costruttore Vuoto
public Complex()
{
this.real = 0.0;
this.imag = 0.0;
}
public Complex(double real, double imag)
{
this.real = real;
this.imag = imag;
}
public override string ToString()
{
string data = real.ToString() + " " + imag.ToString() + "i";
return data;
}
//Converte i valori polari in rettangolari
public static Complex from_polar(double r, double radians)
{
Complex data = new Complex(r * Math.Cos(radians), r * Math.Sin(radians));
return data;
}
//Override l'operatore di addizione
public static Complex operator +(Complex a, Complex b)
{
Complex data = new Complex(a.real + b.real, a.imag + b.imag);
return data;
}
//Override l'operatore di sottrazione
public static Complex operator -(Complex a, Complex b)
{
Complex data = new Complex(a.real - b.real, a.imag - b.imag);
return data;
}
//Override l'operatore di moltiplicazione
public static Complex operator *(Complex a, Complex b)
{
Complex data = new Complex((a. real * b.real ) - (a.imag * b.imag ),(a. real * b.imag + (a.imag * b.real )));
return data;
}
//Ritorna il valore Complesso di Ampiezza
public double magnitude
{
get
{
return Math.Sqrt(Math.Pow(this.real, 2) + Math.Pow(this.imag, 2));
}
}
//Ritorna la fase
public double phase
{
get
{
return Math.Atan(this.imag / this.real);
}
}
}
}