hypersnakuscule.h 2.37 KB
#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