#ifndef RTS_VECTOR_H #define RTS_VECTOR_H #include #include #include //#include "rts/math/point.h" #include "../cuda/callable.h" namespace stim { template struct vec { T v[N]; CUDA_CALLABLE vec() { //memset(v, 0, sizeof(T) * N); for(int i=0; i& other){ for(int i=0; i CUDA_CALLABLE operator vec(){ vec result; for(int i=0; i //friend vec::operator vec(); CUDA_CALLABLE T len() const { //compute and return the vector length T sum_sq = (T)0; for(int i=0; i cart2sph() const { //convert the vector from cartesian to spherical coordinates //x, y, z -> r, theta, phi (where theta = 0 to 2*pi) vec sph; sph[0] = std::sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]); sph[1] = std::atan2(v[1], v[0]); sph[2] = std::acos(v[2] / sph[0]); return sph; } CUDA_CALLABLE vec sph2cart() const { //convert the vector from cartesian to spherical coordinates //r, theta, phi -> x, y, z (where theta = 0 to 2*pi) vec cart; cart[0] = v[0] * std::cos(v[1]) * std::sin(v[2]); cart[1] = v[0] * std::sin(v[1]) * std::sin(v[2]); cart[2] = v[0] * std::cos(v[2]); return cart; } CUDA_CALLABLE vec norm() const { //compute and return the vector norm vec result; //compute the vector length T l = len(); //normalize for(int i=0; i cross(const vec rhs) const { vec result; //compute the cross product (only valid for 3D vectors) result[0] = v[1] * rhs.v[2] - v[2] * rhs.v[1]; result[1] = v[2] * rhs.v[0] - v[0] * rhs.v[2]; result[2] = v[0] * rhs.v[1] - v[1] * rhs.v[0]; return result; } CUDA_CALLABLE T dot(vec rhs) const { T result = (T)0; for(int i=0; i operator+(vec rhs) const { vec result; for(int i=0; i operator+(T rhs) const { vec result; for(int i=0; i operator-(vec rhs) const { vec result; for(int i=0; i operator*(T rhs) const { vec result; for(int i=0; i operator/(T rhs) const { vec result; for(int i=0; i operator*=(T rhs){ for(int i=0; i & operator=(T rhs){ for(int i=0; i CUDA_CALLABLE vec & operator=(vec rhs){ for(int i=0; i operator-() const{ vec r; //negate the vector for(int i=0; i rhs) const { if ( (rhs.v[0] == v[0]) && (rhs.v[1] == v[1]) && (rhs.v[2] == v[2]) ) return true; return false; } std::string str() const { std::stringstream ss; ss<<"["; for(int i=0; i std::ostream& operator<<(std::ostream& os, stim::vec v) { os< CUDA_CALLABLE stim::vec operator*(T lhs, stim::vec rhs) { stim::vec r; return rhs * lhs; } //#if __GNUC__ > 3 && __GNUC_MINOR__ > 7 //template using rtsVector = rts::vector; //#endif #endif