#ifndef SNAKUSCULE_H #define SNAKUSCULE_H template 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 operator= (const point &rhs) { this->x = rhs.x; this->y = rhs.y; this->z = rhs.z; return (*this); } CUDA_CALLABLE point operator+ (const point rhs) { point temp; temp.x = this->x + rhs.x; temp.y = this->y + rhs.y; temp.z = this->z + rhs.z; return temp; } CUDA_CALLABLE point operator- (const point rhs) { point temp; temp.x = this->x - rhs.x; temp.y = this->y - rhs.y; temp.z = this->z - rhs.z; return temp; } CUDA_CALLABLE point operator*(const float rhs) { return point(rhs * this->x, rhs * this->y, rhs * this->z ); } CUDA_CALLABLE point operator/ (const float rhs) { return point(this->x / rhs , this->y / rhs, this->z/ rhs ); } }; class sphere { public: point p; point 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 p() { return point(center.x - radius, center.y); } //CUDA_CALLABLE point q() { return point(center.x + radius, center.y); } //CUDA_CALLABLE point c() { return center; } CUDA_CALLABLE point c() { point center; point 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 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 energyGradp , point 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 center = c(); ss << "c = (" << center.x << ", " << center.y << ", " << center.z << ")" << std::endl; ss << "r = " << r() << std::endl; return ss.str(); } }; #endif