Скачиваний:
50
Добавлен:
01.05.2014
Размер:
4.56 Кб
Скачать
#include<iostream.h>
#include<math.h>
#include<values.h>
#include<conio.h>

#include "Kvadrat.h"

//Konstuktor
  Kvadrat::Kvadrat(int _X,int _Y,int _Lmax,int _Lmin,double Fi,double Fi0,int _V,double _A,double _Angle)
		:Planeta(_X,_Y,_Lmax,_Lmin,Fi,Fi0,_V)
	{if (_A>0) {A=_A;}
		else {cout<<"Storona doljna bit bolshe 0"<<endl;A=1;}
	 Angle=_Angle;
	 }

//Selectori
double Kvadrat::getX() const
	{double Xp,Yp,Xt;
	 Xp=Planeta::getLmax()*cos(Planeta::getFi0());

	 if (Planeta::getFi0()<=3.14)
	 {Yp=Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
	 else
	 {Yp=0-Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}

	 if (Xp!=0) {
	  Xt=sqrt(Xp*Xp+Yp*Yp)*cos(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getX();
	  }else {
	  Xt=sqrt(Xp*Xp+Yp*Yp)*cos(3.14+Planeta::getAngle())+Planeta::getX();
	  }

	  if ((Planeta::getFi0()<=1.57)||(Planeta::getFi0()>=4.71)) {Xt=sqrt(Xt*Xt);}
	  else {Xt=0-sqrt(Xt*Xt);}

	  return Xt;
	  }

double Kvadrat::getY() const
	{double Xp,Yp,Yt;
	 Xp=Planeta::getLmax()*cos(Planeta::getFi0());

	 if (Planeta::getFi0()<=3.14)
	 {Yp=Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
	 else
	 {Yp=0-Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}

	 if (Xp!=0) {
	  Yt=sqrt(Xp*Xp+Yp*Yp)*sin(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getY();
	  }else {
	  Yt=sqrt(Xp*Xp+Yp*Yp)*sin(3.14+Planeta::getAngle())+Planeta::getY();
	  }

	  if (Planeta::getFi0()<=3.14) {Yt=sqrt(Yt*Yt);}
	  else {Yt=0-sqrt(Yt*Yt);}

	  return Yt;
	  }

  double Kvadrat::getXpt(double t) const
	{double Xp,Yp,Xt;
	 if (t==0) {Xt=getX();}
	 else {
	  Xp=Planeta::getLmax()*cos(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
	  Yp=Planeta::getLmin()*sin(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());

	  if (Xp!=0) {
	  Xt=sqrt(Xp*Xp+Yp*Yp)*cos(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getX();
	  }else {
	  Xt=sqrt(Xp*Xp+Yp*Yp)*cos(3.14+Planeta::getAngle())+Planeta::getX();
	  }}
	  return Xt;
	  }

  double Kvadrat::getYpt(double t) const
	{double Xp,Yp,Yt;
	 if (t==0) {Yt=getY();}
	 else {
	  Xp=Planeta::getLmax()*cos(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
	  Yp=Planeta::getLmin()*sin(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());

	  if (Xp!=0) {
	  Yt=sqrt(Xp*Xp+Yp*Yp)*sin(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getY();
	  }else {
	  Yt=sqrt(Xp*Xp+Yp*Yp)*sin(3.14+Planeta::getAngle())+Planeta::getY();
	  }}
	  return Yt;
	  }

double Kvadrat::getA() const
	{return A/1.41;}

double Kvadrat::getArea() const
	{return A*A;}

double Kvadrat::getAngle() const
	{return Angle;}

void Kvadrat::Print() const
	{cout<<endl<<"------Planeta Kvadrat-----"<<endl;
	 cout<<"Adres: "<<getAdr().getAdress()<<endl;
	 cout<<"-Nachalnie koordinati: "<<endl;
	 cout<<"Ugol otkloneniya: "<<Planeta::getFi0()<<endl;
	 cout<<"X:    "<<Kvadrat::getX()<<endl;
	 cout<<"Y:    "<<Kvadrat::getY()<<endl;
	 cout<<"A:    "<<A<<endl;
	 cout<<"Area: "<<getArea()<<endl;
	 cout<<"Naklon: "<<Angle<<endl;
	 cout<<"---------------------------"<<endl;
	 cout<<"Skorost' planeti: "<<abs(Planeta::getV())<<endl;
	 if (Planeta::getV()>0) {cout<<"Po chasovoy strelke"<<endl;}
	 else {cout<<"Protiv chasovoy strelki"<<endl;}
	 }

void Kvadrat::PrintS(double t) const
	{Planeta::Print();

	 if (t!=0) {
	  cout<<"Koordinati cherez "<<t<<" sekund:"<<endl;
	  cout<<"X: "<<getXpt(t)<<endl;
	  cout<<"Y: "<<getYpt(t)<<endl<<endl;};
	 Print();
	 }

//Modifikatori
void Kvadrat::Revol(double dFi)
	{Angle=Angle+dFi;}

void Kvadrat::Masht(double dN)
	{if (dN>0)
		{A=A*dN;}
	 else {cout<<"Dlina doljna bit bolshe 0"<<endl;getch();}
	}

void Kvadrat::Move(double dX,double dY)
	{}

void Kvadrat::RevolO(double dFi)
	{Planeta::Revol(dFi);}

void Kvadrat::MashtO(double dN)
	{Planeta::Masht(dN);}


void Kvadrat::MoveO(double dX,double dY)
	{Planeta::Move(dX,dY);}

void Kvadrat::Receive(Message Msg)	            //Prinat soobshenie
	{cout<<"======================="<<endl;
	 cout<<"Klient "<<getAdr().getAdress()<<" prinal soobshenie "<<endl
	     <<"ot klienta "<<Msg.getOtp().getAdress()<<endl;
	 cout<<"Soobshenie: "<<Msg.getMsg()<<endl;
	 cout<<"-----------------------"<<endl;
	 cout<<"Kvadrat"<<endl;
	 cout<<"Moi koordinati v eto vrama:"<<endl;
	 cout<<"X: "<<getXpt(Msg.getMsg())<<endl;
	 cout<<"Y: "<<getYpt(Msg.getMsg())<<endl;
	 cout<<"======================="<<endl;
	 }
Соседние файлы в папке Kurs3