#ifndef VECT3D_H_ #define VECT3D_H_ #include #include typedef struct v3 //3d vector struct with overloaded operators { double x,y,z; inline v3() {x=y=z= 0.0;} inline v3(double vx, double vy, double vz) { x=vx; y=vy; z=vz; } inline v3(const v3 &v) {x=v.x; y=v.y; z=v.z;} v3& operator=(const v3 &rhs) {x=rhs.x; y=rhs.y; z=rhs.z; return *this;} inline v3& operator+=(const v3 &rhs) {x+=rhs.x; y+=rhs.y; z+=rhs.z; return *this;} inline v3& operator-=(const v3 &rhs) {x-=rhs.x; y-=rhs.y; z-=rhs.z; return *this;} inline v3& operator*=(const v3 &rhs) {x*=rhs.x; y*=rhs.y; z*=rhs.z; return *this;} inline v3& operator/=(const v3 &rhs) {x/=rhs.x; y/=rhs.y; z/=rhs.z; return *this;} //scalar mult/div inline v3& operator*=(const double s) {x*=s; y*=s; z*=s; return *this;} inline v3& operator/=(const double s) {x/=s; y/=s; z/=s; return *this;} inline const v3 operator+(const v3 &rhs) const {v3 v(*this); return v+=rhs;} inline const v3 operator-(const v3 &rhs) const {v3 v(*this); return v-=rhs;} inline const v3 operator*(const v3 &rhs) const {v3 v(*this); return v*=rhs;} inline const v3 operator/(const v3 &rhs) const {v3 v(*this); return v/=rhs;} inline const v3 operator*(const double s) const {v3 v(*this); return v*=s;} inline const v3 operator/(const double s) const {v3 v(*this); return v/=s;} } Vect3D_t; //scalar vector multiplication s * v inline const v3 operator*(const double s, const v3 &rhs) {return rhs*s;} //output stream operator for Vect3D_t (handy for printing) inline std::ostream& operator<<(std::ostream& os, const Vect3D_t& v ) { stringstream ss; ss << fixed << setprecision(2) << "(" << v.x << ", " << v.y << ", " << v.z << ")"; return os << ss.str(); } #endif //VECT3D_H_