Browse Source

first com

Dmitry 3 years ago
commit
1d06bfdf9c
8 changed files with 724 additions and 0 deletions
  1. 157 0
      MyVector3.cpp
  2. 91 0
      MyVector3.h
  3. 172 0
      cCollider.cpp
  4. 32 0
      cCollider.h
  5. 156 0
      cParticle.cpp
  6. 35 0
      cParticle.h
  7. 53 0
      const_def_cPartic.h
  8. 28 0
      main.cxx

+ 157 - 0
MyVector3.cpp

@@ -0,0 +1,157 @@
+
+#include <iostream>
+#include "MyVector3.h"
+
+
+//========================================
+cMyVector3::cMyVector3 () : 
+fX (0.0), fY (0.0), fZ (0.0) {}
+
+cMyVector3::cMyVector3 (double x_, double y_, double z_) :
+fX (x_), fY (y_), fZ (z_) {}
+
+cMyVector3::cMyVector3 (const double *array, int starter) :
+fX (array[0 + starter]), fY (array[1 + starter]), fZ (array[2 + starter]) {}
+
+cMyVector3::~cMyVector3() {}
+
+//=========================================
+
+double cMyVector3::operator () (int i) const{
+   //dereferencing operator
+   switch(i) {
+      case 0:
+         return fX;
+      case 1:
+         return fY;
+      case 2:
+         return fZ;
+      default:
+         std::cout << "not right i \n";
+   }
+   return fX;
+}
+
+//=========================================
+		inline double cMyVector3::x ()  const { return fX; }
+		inline double cMyVector3::y ()  const { return fY; }
+		inline double cMyVector3::z ()  const { return fZ; }
+		inline double cMyVector3::X ()  const { return fX; }
+		inline double cMyVector3::Y ()  const { return fY; }
+		inline double cMyVector3::Z ()  const { return fZ; }
+		inline double cMyVector3::Px () const { return fX; }
+		inline double cMyVector3::Py () const { return fY; }
+		inline double cMyVector3::Pz () const { return fZ; }
+
+//  function for operation with vectors
+									 
+cMyVector3 operator + (const cMyVector3 &, const cMyVector3 &); // +
+
+cMyVector3 operator - (const cMyVector3 &, const cMyVector3 &); // +
+
+double operator * (const cMyVector3 &, const cMyVector3 &); // +
+
+cMyVector3 operator * (const cMyVector3 &, double a);  // +
+
+cMyVector3 operator * (double a, const cMyVector3 &); // +
+
+//cMyVector3 operator * (const TMatrix &, const cMyVector3 &);
+
+//---------------------------------------------------------------------------------------------------
+//=========================================
+inline void cMyVector3::SetXYZ (double x_, double y_, double z_) {
+   fX = x_;
+   fY = y_;
+   fZ = z_;
+}
+//=========================================
+
+inline void cMyVector3::SetX (double xx) { fX = xx; }
+inline void cMyVector3::SetY (double yy) { fY = yy; }
+inline void cMyVector3::SetZ (double zz) { fZ = zz; }
+
+//=========================================
+inline cMyVector3 & cMyVector3::operator = (const cMyVector3 & p) {
+   fX = p.fX;
+   fY = p.fY;
+   fZ = p.fZ;
+   return *this;
+}
+
+//=========================================
+inline void cMyVector3::GetXYZ (double *carray, int starter) const {
+   carray [0 + starter] = fX;
+   carray [1 + starter] = fY;
+   carray [2 + starter] = fZ;
+}
+//---------------------------------------------------------------------------------------------------
+
+//=========================================
+inline double cMyVector3::Dot(const cMyVector3 & p) const {
+   return fX*p.fX + fY*p.fY + fZ*p.fZ;
+}
+
+//=========================================
+inline bool cMyVector3::operator == (const cMyVector3& v) const {
+   return (v.fX == fX && v.fY == fY && v.fZ == fZ) ? true : false;
+}
+
+//=========================================
+inline bool cMyVector3::operator != (const cMyVector3& v) const {
+   return (v.fX != fX || v.fY != fY || v.fZ != fZ) ? true : false;
+}
+
+//=========================================
+inline cMyVector3& cMyVector3::operator += (const cMyVector3 & p) {
+   fX += p.fX;
+   fY += p.fY;
+   fZ += p.fZ;
+   return *this;
+}
+
+//=========================================
+inline cMyVector3& cMyVector3::operator -= (const cMyVector3 & p) {
+   fX -= p.fX;
+   fY -= p.fY;
+   fZ -= p.fZ;
+   return *this;
+}
+
+//=========================================
+inline cMyVector3 cMyVector3::operator - () const {
+   return cMyVector3(-fX, -fY, -fZ);
+}
+
+//=========================================
+inline cMyVector3& cMyVector3::operator *= (double a) {
+   fX *= a;
+   fY *= a;
+   fZ *= a;
+   return *this;
+}
+
+//=========================================
+cMyVector3 operator + (const cMyVector3 & a, const cMyVector3 & b) {
+   return cMyVector3 (a.X() + b.X(), a.Y() + b.Y(), a.Z() + b.Z());
+}
+
+//=========================================
+cMyVector3 operator - (const cMyVector3 & a, const cMyVector3 & b) {
+   return cMyVector3 (a.X() - b.X(), a.Y() - b.Y(), a.Z() - b.Z());
+}
+
+//=========================================
+cMyVector3 operator * (const cMyVector3 & p, double a) {
+   return cMyVector3 (a*p.X(), a*p.Y(), a*p.Z());
+}
+
+//=========================================
+cMyVector3 operator * (double a, const cMyVector3 & p) {
+   return cMyVector3 (a*p.X(), a*p.Y(), a*p.Z());
+}
+
+//=========================================
+double operator * (const cMyVector3 & a, const cMyVector3 & b) {
+   return a.Dot(b);
+}
+

+ 91 - 0
MyVector3.h

@@ -0,0 +1,91 @@
+#ifndef MYVECTOR3_H_
+#define MYVECTOR3_H_
+
+class cParticle;
+
+class cMyVector3 {
+	
+	public:
+		
+		cMyVector3 (); // +
+		cMyVector3 (double x_, double y_, double z_); // +
+		
+		cMyVector3 (const double *array, int starter = 0); // +
+		   
+		~cMyVector3 (); // not realised
+		
+		double operator () (int i) const; // +
+		
+		//inline Double_t operator [] (int) const; // not realised
+		
+		//Function for add numbers
+
+		inline double x ()  const; // +
+		inline double y ()  const; // +
+		inline double z ()  const; // +
+		inline double X ()  const; // +
+		inline double Y ()  const; // +
+		inline double Z ()  const; // +
+		inline double Px () const; // +
+		inline double Py () const; // +
+		inline double Pz () const; // +
+		
+		inline void SetX (double);// +
+		inline void SetY (double);// +
+		inline void SetZ (double);// +
+		inline void SetXYZ (double x_, double y_, double z_); // +
+
+// *** funny good things	
+		inline void GetXYZ (double *carray, int starter = 0) const; // +
+   
+    inline double  Dot (const cMyVector3 &) const;
+// *** Not realised, do if you want  
+/*
+		void SetPtEtaPhi (Double_t pt, Double_t eta, Double_t phi);
+		void SetPtThetaPhi (Double_t pt, Double_t theta, Double_t phi);
+		
+		Double_t Phi () const;
+		Double_t Theta () const;
+		
+		inline Double_t CosTheta () const;
+		inline Double_t Mag2 () const;
+		
+		Double_t Mag () const;
+		void SetPhi (Double_t);
+		
+		void SetTheta (Double_t);
+		inline void SetMag (Double_t);
+		
+		inline Double_t Perp2 () const;
+		inline Double_t Pt () const;
+		
+		Double_t Perp () const;
+		inline void SetPerp (Double_t);
+*/
+// *** end
+	
+		inline cMyVector3 & operator = (const cMyVector3 &); // +
+	  
+		inline bool operator == (const cMyVector3 &) const; // +
+                                                          
+		inline bool operator != (const cMyVector3 &) const; // +
+		
+		inline cMyVector3 & operator += (const cMyVector3 &); // +
+		
+		inline cMyVector3 & operator -= (const cMyVector3 &); // +
+		
+		inline cMyVector3 operator - () const; // +
+		
+		inline cMyVector3 & operator *= (double); // +
+   
+	private:
+		
+		double fX, fY, fZ;
+	
+};
+
+
+
+
+
+#endif

+ 172 - 0
cCollider.cpp

@@ -0,0 +1,172 @@
+#include <iostream>
+#include <assert.h>
+#include <cmath>
+
+#include "MyVector3.h"
+#include "cCollider.h"
+#include "const_def_cPartic.h"
+#include <cerrno> 
+using std::cout;
+using std::endl;
+using std::abs;
+//==============================
+/*
+cCollider::cCollider (cParticle particle_) {
+	
+		//m_part [0] = new cParticle;
+		//m_counter = 0;
+		//m_time = 0;
+	
+}
+*/
+//==============================
+cCollider::cCollider  (int N_, part_param param_, int pointer_) {
+		m_counter = 0;
+		m_part.resize (10);
+	for (int i = pointer_; i < N_; i++) {
+		//111111111111111111111111111111111
+			//m_part [i] = new cParticle (param_.x, param_.y, param_.z, param_.mass, param_.radii, param_.px, param_.py, param_.pz);
+		//2222222222222222222222222222222
+		//	m_part.push_back (new cParticle (param_.x, param_.y, param_.z, param_.mass, param_.radii, param_.px, param_.py, param_.pz));
+		//3333333333333333333333333333333
+		
+			m_part [i] = new cParticle (param_.x, param_.y, param_.z, param_.mass, param_.radii, param_.px, param_.py, param_.pz);
+		//==============================
+		m_counter++;
+	}
+	m_time = 0;
+} 
+//==============================
+cCollider::~cCollider () {
+	for (int i = 0; i < m_counter; i++) {	
+		if (m_part [i] != NULL) {
+				delete   m_part[i];
+		} 	
+	}
+}
+
+//==============================
+bool cCollider::show () {
+	
+	cout << "m_counter" << m_counter; IF_ERROR_SHOW_( m_counter,  "m_counter")
+	cout << "m_time" << m_time; IF_ERROR_SHOW_( m_time,  "m_time")
+	
+	for (int i = 0; i <= m_counter; i++ ) {
+		m_part [0]->show ();
+	}
+}
+
+//==============================
+bool cCollider::Ok () {
+	
+	IF_ERROR_SHOW_( m_counter,  "m_counter")
+	IF_ERROR_SHOW_( m_time,  "m_time")
+	
+	for (int i = 0; i <= m_counter; i++ ) {
+		m_part [0]->Ok ();
+	}
+}
+
+//==============================
+rezalt_collider cCollider::collision (rezalt_collider rezalt_) {
+		
+		
+		if (m_counter = 0) {
+			processing_error (one_part_in_collid);
+			errno = 125; 		// ECANCELED
+			return rezalt_;
+		}
+		
+		cMyVector3 dist1;
+		cMyVector3 dist2;
+		
+		for (int i = 0; i < m_counter; i++) {
+			for (int j = (i + 1); j <= m_counter; j++ ) {
+				dist1 =	m_part [i]->return_coordin ();
+				dist2 = m_part [j]->return_coordin ();
+				if ((m_part [i]->return_radii () + m_part [j]->return_radii ()) < (abs (dist1.X() - dist2.X()))) {
+						errno = 0;
+						return creat_rezalt_of_collid (rezalt_,i, j);
+				}
+				if ((m_part [i]->return_radii () + m_part [j]->return_radii ()) < (abs (dist1.Y() - dist2.Y()))) {
+						errno = 0;
+						return creat_rezalt_of_collid (rezalt_,i, j);
+				}
+				if ((m_part [i]->return_radii () + m_part [j]->return_radii ()) < (abs (dist1.Z() - dist2.Z()))) {
+						errno = 0;
+						return creat_rezalt_of_collid (rezalt_,i, j);
+				}
+			}
+		}
+		
+		errno = 10;		//ECHILD	
+		return rezalt_;
+}
+
+//==============================
+rezalt_collider cCollider::creat_rezalt_of_collid (rezalt_collider rezalt_, int i_, int j_) {
+	
+	/*
+	 * mast to do 
+	 * maybe it will do by Stepan ???
+		*/
+	return rezalt_;
+}
+
+//==============================
+bool 	cCollider::processing_error (const int namb_Of_error) {
+	
+	#define IF_ERROR_NUMBER_COLLIDER_(err, text) \
+				if (namb_Of_error == err) {     \
+					cout << text << endl;       \
+					return true; 								\
+				}	
+	
+	 IF_ERROR_NUMBER_COLLIDER_(one_part_in_collid,
+		"One particle in collider not enough to impinge \n")
+	
+	 IF_ERROR_NUMBER_COLLIDER_(time_to_collide_passid,
+		"Time to collisions has passed \n")
+	#undef IF_ERROR_NUMBER_COLLIDER_
+}
+
+//==============================
+rezalt_collider cCollider::step (int count_, rezalt_collider rezalt_, double size_of_step_ , bool start_) {
+	
+	collision (rezalt_);
+	if (errno == 125) {
+			cout << "I cannot collide one particl \n";
+			return rezalt_;
+	}
+	
+	cMyVector3 speed;
+	cMyVector3 coordin_old;
+	cMyVector3 coordin_new;
+	
+	double px, py, pz;
+	double x, y, z;
+	while (start_ && (errno == 10)) {
+		for (int i = 0; i <= m_counter; i++) {
+			speed = m_part [i]->return_speed ();
+			px = size_of_step_ * speed.X ();
+			py = size_of_step_ * speed.Y ();
+			pz = size_of_step_ * speed.Z ();
+		
+			coordin_old = m_part [i]->return_coordin ();
+			x = coordin_old.X ();
+			y = coordin_old.Y ();
+			z = coordin_old.Z ();
+			
+			coordin_new.SetXYZ (x, y, z);
+			m_part [i]->change_coordin (coordin_new);
+		} //end of for
+		m_time++;
+		collision (rezalt_);
+		if (m_time == time_to_collide_passid) {
+				start_ = false;
+				processing_error (time_to_collide_passid);
+		}
+	}	// end of while
+
+	return rezalt_;
+}

+ 32 - 0
cCollider.h

@@ -0,0 +1,32 @@
+#ifndef cCOLLIDER_H_
+#define cCOLLIDER_H_
+#include <vector>
+#include "cParticle.h"
+#include "const_def_cPartic.h"
+
+
+class cCollider {
+	
+		public:
+			cCollider (int N_, part_param param_, int pointer_ = 0);
+			//cCollider (cParticle particle_);
+			~cCollider ();
+			bool show ();
+			bool Ok ();
+			
+			rezalt_collider collision (rezalt_collider rezalt_);
+			rezalt_collider step (int count_, rezalt_collider rezalt_, double size_of_step_ = 1.0, bool start_ = true);
+		
+		private:
+		
+		std::vector <cParticle*>  m_part;
+		double m_time;
+		int m_counter;
+		
+		rezalt_collider creat_rezalt_of_collid (rezalt_collider rezalt_, int i_, int j_);
+		bool 	processing_error (const int namb_Of_error);
+		
+};
+
+
+#endif 

+ 156 - 0
cParticle.cpp

@@ -0,0 +1,156 @@
+#include <iostream>
+#include <assert.h>
+
+#include "cParticle.h"
+#include "const_def_cPartic.h"
+
+using std::cout;
+using std::endl;
+//==============================
+cParticle::cParticle (double x_, double y_, double z_, double mass_, double radii_, double px_, double py_, double pz_) {
+	
+	m_mass = mass_;
+	m_radii = radii_;
+	
+	m_coordin.SetX (x_);
+	m_coordin.SetY (y_);
+	m_coordin.SetZ (z_);
+	
+	m_speed.SetX (px_);
+	m_speed.SetY (py_);
+	m_speed.SetZ (pz_);
+	
+}
+
+//==============================
+cParticle::~cParticle () {
+	
+	cout << "I am  a distruction, I delit your Particle \n";
+	
+}
+
+//==============================
+bool cParticle::show () {
+/*	
+#define IF_ERROR_SHOW_(variable, msg)	if (variable < 0)	{ \
+																	cout << "ERROR!!!" << endl; \
+																	cout << msg << "< 0" << endl; \
+																	cout << __FILE__ << endl; \
+																	cout << _FUNC_<< "   " << __LINE__ << endl; \
+																	return false; \
+																} \
+																else cout << endl; \
+																	return true; 
+*/	 	
+		cout << __FILE__ << "   "<< _FUNC_ << endl;
+		
+		cout << "m_mass = " << m_mass; IF_ERROR_SHOW_(m_mass, "m_mass")
+		cout << "m_radii_ = " << m_radii; IF_ERROR_SHOW_(m_radii, "m_radii_")
+
+		cout << "m_coordin X = " << m_coordin.X () << endl;
+		cout << "m_coordin Y = " << m_coordin.Y () << endl;
+		cout << "m_coordin Z = " << m_coordin.Z () << endl; 
+		 
+		cout << "m_speed X = " << m_speed.X () << endl;	
+		cout << "m_speed Y = " << m_speed.Y () << endl;	
+		cout << "m_speed Z = " << m_speed.Z () << endl;	
+	 
+//#undef IFERROR_SHOW_		
+ 	
+}
+
+//==============================
+bool cParticle::Ok () {
+	
+	IF_ERROR_SHOW_(m_mass, "m_mass")
+	IF_ERROR_SHOW_(m_radii, "m_radii_")
+	
+	
+}
+
+//==============================
+cMyVector3 cParticle::return_coordin () {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+		
+	return m_coordin;	
+}
+
+//==============================
+cMyVector3 cParticle::return_speed () {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+
+	return m_speed;
+}
+
+//==============================
+double cParticle::return_mass () {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+	return m_mass;
+}
+
+//==============================
+double cParticle::return_radii () {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+
+	return m_radii;
+}
+
+//==============================
+void cParticle::change_coordin (cMyVector3 new_coordin) {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+	
+		m_coordin = new_coordin;4
+		
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+}
+
+//==============================
+void cParticle::change_speed (cMyVector3 new_speed) {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+
+		m_speed = new_speed;
+
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_()
+#endif
+}
+
+//==============================
+void cParticle::change_mass (double  new_mass) {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_();
+#endif
+
+		m_mass = new_mass;
+
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_();
+#endif
+}
+
+//==============================
+void cParticle::change_radii (double new_radii) {
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_();
+#endif
+
+		m_radii = new_radii;
+
+#ifdef USE_SUPER_PUPER_GUARDS	
+	_ASSERT_OK_();
+#endif
+}

+ 35 - 0
cParticle.h

@@ -0,0 +1,35 @@
+#ifndef cPARTICLE_H_
+#define cPARTICLE_H_
+
+#include "MyVector3.h"
+//class cMyVector3;
+
+class cParticle {
+	
+	public:
+	
+		cParticle (double x_, double y_, double z_, double mass_, double radii_, double px_, double py_, double pz_);
+		~cParticle 	();
+		bool show 	();
+		bool Ok 		();
+	
+		cMyVector3 return_coordin ();
+		cMyVector3 return_speed ();
+		double 	 return_mass ();
+		double   return_radii ();
+		
+		void change_coordin (cMyVector3 new_coordin);
+		void change_speed 	(cMyVector3 new_speed);
+		void change_radii 	(double new_radii);
+		void change_mass 		(double new_mass);
+	
+	private:
+	
+		cMyVector3 m_coordin;
+		double m_mass;
+		double m_radii;
+		cMyVector3 m_speed;
+
+
+};
+#endif

+ 53 - 0
const_def_cPartic.h

@@ -0,0 +1,53 @@
+#ifndef CONST_DEF_CPARTIC_H_
+#define CONST_DEF_CPARTIC_H_
+
+//========================================
+#ifdef _MSC_VER
+		#define _FUNC_  __FUNCTION__
+	#elif __GNUC__
+		#define _FUNC_  __PRETTY_FUNCTION__
+	#endif	
+	
+//========================================	
+#define IF_ERROR_SHOW_(variable, msg)	if (variable < 0)	{ \
+																	cout << "ERROR!!!" << endl; \
+																	cout << msg << "< 0" << endl; \
+																	cout << __FILE__ << endl; \
+																	cout << _FUNC_<< "   " << __LINE__ << endl; \
+																	return false; \
+																} \
+																else cout << endl; \
+																	return true; 
+																	
+//========================================		
+	#define _DEBUG_ASSERT_(msg) cout << _FUNC_ << ":" << msg; assert(0);
+	#define _ASSERT_OK_(); if (!this->Ok ()) { \
+						this->show (); \
+						_DEBUG_ASSERT_("Not Ok!") \
+					} 
+
+					
+//========================================		
+#define  USE_SUPER_PUPER_GUARDS	
+
+const int one_part_in_collid = -111;
+unsigned const int time_to_collide_passid = 999999999;
+//========================================		
+struct part_param {
+	double x;	
+	double y;
+	double z;
+	double mass;
+	double radii;
+	double px;
+	double py; 
+	double pz;
+
+};
+
+struct rezalt_collider {
+	int t;
+}	;
+
+												
+#endif

+ 28 - 0
main.cxx

@@ -0,0 +1,28 @@
+#include  <iostream>
+
+#include "cCollider.h"
+#include "const_def_cPartic.h"
+
+using std::cout;
+
+int main () {
+	
+	part_param part_one;
+	part_one.x = 0;
+	part_one.y = 1;
+	part_one.z = 0;
+	
+	part_one.px = 1;
+	part_one.py = 0;
+	part_one.pz = 0;
+	
+	part_one.mass = 1;
+	part_one.radii = 1;
+	
+	cCollider collid1 (1, part_one, 0);
+	
+	cout << "IIII Ok \n";
+	
+
+return 0;	
+}