Blame view

hypersnakuscule.h 2.37 KB
f6438346   Mahsa Lotfollahi   initial commit af...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  #ifndef SNAKUSCULE_H
  #define SNAKUSCULE_H
  
  template <typename T >
  class point {
  public:
  
  	T x;
  	T y;
  	T z; 
  
  	//default constructor
  	CUDA_CALLABLE point() {
  		x = 0;
  		y = 0;
  		z = 0;
  	};
  	//constructor definition 
  	CUDA_CALLABLE point(T a, T b, T c) {
  		x = a;
  		y = b;
  		z = c; 
  	}
  
  	CUDA_CALLABLE point <T> operator= (const point<T> &rhs) {
  		this->x = rhs.x;
  		this->y = rhs.y;
  		this->z = rhs.z; 
  		return (*this);
  	}
  
  	CUDA_CALLABLE point <T> operator+ (const point<T> rhs) {
  		point<T> temp;
  		temp.x = this->x + rhs.x;
  		temp.y = this->y + rhs.y;
  		temp.z = this->z + rhs.z;
  		return temp;
  
  	}
  
  	CUDA_CALLABLE point<T> operator- (const point<T> rhs) {
  		point<T> temp;
  		temp.x = this->x - rhs.x;
  		temp.y = this->y - rhs.y;
  		temp.z = this->z - rhs.z;
  		return temp;
  
  	}
  	CUDA_CALLABLE point<T> operator*(const float rhs) {
  		return point(rhs * this->x, rhs * this->y, rhs * this->z );
  	}
  
  
  	CUDA_CALLABLE point<T> operator/ (const float rhs) {
  		return point(this->x / rhs , this->y / rhs, this->z/ rhs );
  
  	}
  };
  
  
  class sphere {
  
  public:
  
  	point<float> p;
  	point<float> q;
  	//default constructor
  	CUDA_CALLABLE sphere() {
  		p.x = 0;
  		p.y = 0;
  		p.z = 0;
  		q.x = 0;
  		q.y = 0;
  		q.z = 0;
  	};
  
  	//CUDA_CALLABLE point<float> p() { return point<float>(center.x - radius, center.y); }
  	//CUDA_CALLABLE point<float> q() { return point<float>(center.x + radius, center.y); }
  	//CUDA_CALLABLE point<float> c() { return center; }
  	CUDA_CALLABLE point<float> c() {
  		point<float> center;
  		point<float> sum; // sum of two points to get center
  		sum = p + q;
  		center.x = 0.5f * sum.x;
  		center.y = 0.5f * sum.y;
  		center.z = 0.5f * sum.z;
  		return center; }
  
  	//CUDA_CALLABLE float r() { return radius; }
  	CUDA_CALLABLE float r() { 
  		float radius;
  		point <float> d; //distance
  		d = p - q;
  		radius = 0.5f* sqrt((d.x * d.x) + (d.y * d.y) + (d.z * d.z));
  		return radius; }
  
  	CUDA_CALLABLE void update(point<float> energyGradp , point<float> energyGradq , float dt){
  		p = p - (energyGradp * dt);
  		q = q - (energyGradq * dt);
  	}
  
  	CUDA_UNCALLABLE std::string str() {
  		std::stringstream ss;
  		ss << "q = (" << q.x << ", " << q.y << ", " << q.z << ")" << std::endl;
  		ss << "p = (" << p.x << ", " << p.y << ", " << p.z << ")" << std::endl;
  		point<float> center = c();
  		ss << "c = (" << center.x << ", " << center.y << ", " << center.z << ")" << std::endl;
  		ss << "r = " << r() << std::endl;
  		return ss.str();
  	}
  };
  
  #endif