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

class Point
{
 private: float x,  //ЂЎбжЁбб  в®зЄЁ
		y;  //Ћа¤Ё­ в  в®зЄЁ
	 double R,  //ђ ббв®п­ЁҐ ¤® ­ з «  Є®®а¤Ё­ в
		 Fi; //“Ј®« Ї®ў®а®в  ®в ®бЁ  ЎбжЁбб
		 void XYtoRFi();  //ЏаҐ®Ўа §®ў ­ЁҐ ў Ї®«па­лҐ Є®®а¤Ё­ вл
		 void RFitoXY();  //ЏаҐ®Ўа §®ў ­ЁҐ ў ¤ҐЄ ав®ўл Є®®а¤Ё­ вл
		 int invariant(); //Џа®ўҐаЄ 

 public:
			Point(float, float);
			void SetXY(float x0=0, float y0=0);            //€§¬Ґ­Ёвм Є®®а¤Ё­ вл
			void GetXY(float &x0, float &y0);              //Џ®«гзЁвм Є®®а¤Ё­ вл
			void GetRFi(double &R0, double &Fi0);          //Џ®«гзЁвм ¬®¤г«м Ё  аЈг¬Ґ­в
			void Rotate(float x1, float y1, double Fi0);   //Џ®ўҐа­гвм ­  гЈ®« ў®ЄагЈ в®зЄЁ  1
			void Move(float dx, float dy);                 //ЏҐаҐ­ҐбвЁ ў § ¤ ­­®¬  ­ Їа ў«Ґ­ЁЁ
			void Mirror(Point);                            //‡ҐаЄ «м­® ®в®Ўа §Ёвм ®в­. в®зЄЁ 1
			~Point();                                      //“­Ёз⮦Ёвм в®зЄг
};

///////////////////////////////////////////////////////////////
inline void Point::SetXY(float x0, float y0)     //Њ®¤ЁдЁЄ в®а Є®®а¤Ё­ в
{
 x=x0; y=y0;
}
////////////////////////////////////////////////////////////////
inline void Point::GetXY(float &x0, float &y0)    //‘Ґ«ҐЄв®а Є®®а¤Ё­ в
{
 x0=x; y0=y;
}
////////////////////////////////////////////////////////////////
inline void Point::GetRFi(double &R0, double &Fi0)   //‘Ґ«ҐЄв®а ¬®¤г«п Ё  аЈг¬Ґ­в 
{
 R0=R; Fi0=Fi;
}
/////////////////////////////////////////////////////////////////
inline Point::Point(float x0, float y0)
{
 if((x0>MAXFLOAT)||(x0<-MAXFLOAT)||(y0>MAXFLOAT)||(y0<-MAXFLOAT))
 {
	cout<<"‡­ зҐ­Ёп ўл室пв §  а ¬ЄЁ ¤Ё Ї §®­ "<<endl;
	getch();
	exit(1);
 }
 SetXY(x0, y0);
 XYtoRFi();
// cout<<"’®зЄ  ᮧ¤ ­  c Є®®а¤Ё­ в ¬Ё x = "<<x0<<", y = "<<y0;
 if(!invariant())
 {
	cout<<endl<<"Ќ аг襭ЁҐ бвагЄвгал в®зЄЁ"<<endl;
	getch();
	exit(1);
 }
// getch();
}
/////////////////////////////////////////////////////////////////
inline Point::~Point()                              //„ҐбвагЄв®а. “­з⮦Ёвм в®зЄг
{                                                    //ЃҐ§ иг¬г Ё Їл«Ё, Є Є ўЁ¤­® Ё§ Є®¤ 
}
/////////////////////////////////////////////////////////////////
inline void Point::XYtoRFi()                        //‚лзЁб«ЁвҐ«м ¬®¤г«п Ё  аЈг¬Ґ­в 
{                                                   //џ ­Ґ е®вҐ« ў®§Ёвмбп б® ў«®¦Ґ­­л¬Ё
 R = sqrt(x*x+y*y);                                 //гб«®ўЁп¬Ё Ё ў§п« ў «®Ў ЇҐаҐЎ®а®¬
 if((x==0)&&(y==0)) Fi = 0;                         //ђ Ў®в Ґв Їа ўЁ«м­®
 if((x==0)&&(y<0)) Fi = 3*M_PI/2;                   //Ћ¤®ЎаҐ­® ¬­®о
 if((x==0)&&(y>0)) Fi = M_PI/2;
 if((x<0)&&(y==0)) Fi = M_PI;
 if((x>0)&&(y==0)) Fi = 0;
 if((x>0)&&(y>0))  Fi = atan(y/x);
 if((x>0)&&(y<0)) Fi = 3*M_PI/2+atan(fabs(y/x));
 if((x<0)&&(y>0)) Fi = M_PI/2+atan(fabs(y/x));
 if((x<0)&&(y<0)) Fi = M_PI+atan(fabs(y/x));
}
//////////////////////////////////////////////////////////////////
inline void Point::Move(float dx, float dy)               //‘¤ўЁ­гвм в®зЄг ­  dx, dy
{
 float tx, ty;
 GetXY(tx, ty);
 if((dx>MAXFLOAT)||(dx<-MAXFLOAT)||(dy>MAXFLOAT)||(dy<-MAXFLOAT)
		 ||(dx+tx>MAXFLOAT)||(dx+tx<-MAXFLOAT)||(dy+ty>MAXFLOAT)||(dy+ty<-MAXFLOAT))
 {
	cout<<"‡­ зҐ­Ёп ўл室пв §  а ¬ЄЁ ¤Ё Ї §®­ "<<endl;
	getch();
	exit(1);
 }
 SetXY(tx+dx,ty+dy);
 XYtoRFi();
// cout<<"’®зЄ  ЇҐаҐ¬ҐйҐ­  Ї® Ј®аЁ§®­в «Ё ­  "<<dx<<" Ё Ї® ўҐавЁЄ «Ё ­  "<<dy;
//	if(!invariant())
// {
//	cout<<endl<<"Ќ аг襭ЁҐ бвагЄвгал в®зЄЁ"<<endl;
//	getch();
//	exit(1);
// }
}
//////////////////////////////////////////////////////////////////
inline void Point::Rotate(float x1, float y1, double Fi0)
{
 float tx, ty;
 GetXY(tx, ty);
 tx = (tx-x1)*cos(Fi0) - (ty-y1)*sin(Fi0);
 ty = (ty-y1)*cos(Fi0) + (tx-x1)*sin(Fi0);
 SetXY(tx, ty);
 XYtoRFi();
}
//////////////////////////////////////////////////////////////////
inline void Point::Mirror(Point B)                           //‘Ё¬¬ҐваЁз­® ®ва §Ёвм Ђ ®в­®бЁвҐ«м­® ‚
{
 float tx, ty, bx, by;
 GetXY(tx, ty);
 B.GetXY(bx, by);
 if((2*bx-tx>MAXFLOAT)||(2*bx-tx<-MAXFLOAT)||(2*by-ty>MAXFLOAT)||(2*by-ty<-MAXFLOAT))
 {
	cout<<endl<<"‡­ зҐ­Ёп ўл室пв §  а ¬ЄЁ ¤Ё Ї §®­ ";
	getch();
	exit(1);
 }
 SetXY(2*bx-tx, 2*by - ty);
 XYtoRFi();
// cout<<"’®зЄ  §ҐаЄ «м­® ®ва ¦Ґ­  ®в­®бЁвҐ«м­® 業ва  бЁ¬¬ҐваЁЁ б Є®®а¤Ё­ в ¬Ё "<<bx<<" "<<by;
// if(!invariant())
// {
//	cout<<endl<<"Ќ аг襭ЁҐ бвагЄвгал в®зЄЁ";
//	getch();
//	exit(1);
// }
}
//////////////////////////////////////////////////////////////////
inline int Point::invariant()
{
 if((x>MAXFLOAT)||(x<-MAXFLOAT)||(y>MAXFLOAT)||(y<-MAXFLOAT)||(R<0)||(R>MAXDOUBLE)||(Fi<0)||(Fi>2*M_PI)||(x-R*cos(Fi)>0.01)||((y-R*sin(Fi)>0.01)))
	return 0;
 return 1;
}
Соседние файлы в папке Классы Точка и Равнобедренный Треугольник