Добавил:
korayakov
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "UnitComplex.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
CComplex::CComplex(TImage* _Img,int _x,int _y,double _rho,double _phi)
{
Img=_Img;x=_x;y=_y;rho=_rho;phi=_phi;_Marked = false;
Draw();
}
CComplex::CComplex(int _x,int _y,TImage* _Img,double _rx,double _ry)
{
Img=_Img;x=_x;y=_y;rho=sqrt(_rx*_rx+_ry*_ry);phi=atan2l(_ry,_rx);_Marked = false;
Draw();
}
CComplex::~CComplex()
{
Img->Canvas->FillRect(TRect(x-1,y-1,x+w,y+3+h));
/*
Img->Canvas->Brush->Color = clRed;
Img->Canvas->Ellipse(x+w,y+h-5,x+w+5,y+h);
*/
}
void CComplex::Draw()
{
AnsiString Str = FloatToStr(rho)+"*exp(i*"+FloatToStr(phi)+")";
Img->Canvas->Pen->Color = clWhite;
Img->Canvas->Rectangle(x-1,y-1,x+w,y+3+h);
Img->Canvas->Pen->Color = clBlack;
if(!_Marked)
Img->Canvas->Pen->Color = clWhite;
Img->Canvas->Brush->Color = clWhite;
Img->Canvas->Rectangle(x-1,y-1,x+w,y+3+h);
Img->Canvas->Pen->Color = clBlack;
Img->Canvas->TextOutA(x,y,Str);
w = Str.Length()*6;
h = 11;
}
long double CComplex::Angle(CComplex& z)
{
long double temp = (z.phi - phi)*(1-2*(z.phi<phi));
return temp;
// return (temp - (int((temp/(2*pi))))*2*pi);
}
CComplex& CComplex::operator=(CComplex z)
{
rho = z.rho;
phi = z.phi;
Draw();
return *this;
}
CComplex CComplex::operator+(CComplex& z)
{
CComplex temp(z);
long double rx,ry;
rx = z.rho*cos(z.phi)+rho*cos(phi);
ry = z.rho*sin(z.phi)+rho*sin(phi);
temp.rho = sqrt(rx*rx+ry*ry);
temp.phi= atan2l(ry,rx);
return temp;
}
CComplex CComplex::operator-(CComplex& z)
{
CComplex temp(z);
long double rx,ry;
rx = -z.rho*cos(z.phi)+rho*cos(phi);
ry = -z.rho*sin(z.phi)+rho*sin(phi);
temp.rho = sqrt(rx*rx+ry*ry);
temp.phi= atan2l(ry,rx);
return temp;
}
CComplex CComplex::operator*(CComplex& z)
{
CComplex temp(z);
temp.rho = rho*z.rho;
temp.phi= phi+z.phi;
return temp;
}
CComplex CComplex::operator/(CComplex& z)
{
CComplex temp(z);
temp.rho = rho/z.rho;
temp.phi= phi-z.phi;
return temp;
}
ostream& operator<<(ostream& os, const CComplex& z)
{
os<<z.rho << endl << z.phi;
return os;
}
istream& operator>>(istream& is, CComplex& z)
{
is >> z.rho >> z.phi;
return is;
}
Соседние файлы в папке V2