QNANO
Vec3d.h
1 #ifndef QNANO_NEW_CLASS_VEC3D_
2 #define QNANO_NEW_CLASS_VEC3D_
3 
4 #include <cmath>
5 #include <ostream>
6 #include <istream>
7 
9 class Vec3d{
10 public:
11 
13  double v[3];
14 
15 
16 //Functions:
17 
18  inline void set(double x, double y,double z){v[0]=x;v[1]=y;v[2]=z;}
19  inline void set(const Vec3d &other){v[0]=other.v[0];v[1]=other.v[1];v[2]=other.v[2];}
20 
21  inline double norm2() const{return (v[0]*v[0]+v[1]*v[1]+v[2]*v[2]);}
22  inline double norm() const{return sqrt(norm2());}
23  inline void normalize(){double n=norm(); v[0]/=n; v[1]/=n; v[2]/=n;}
24 
25 //Operators:
26  double & operator[](const size_t i){return v[i];}
27  double operator[](const size_t i) const{return v[i];}
28  Vec3d & operator=(const Vec3d &v2);
29  Vec3d & operator+=(const Vec3d &other);
30  Vec3d & operator-=(const Vec3d &other);
31  Vec3d & operator*=(double d);
32  Vec3d & operator/=(double d);
33  friend std::ostream& operator<<(std::ostream& os, const Vec3d& v);
34 
35 //Constructors:
36  Vec3d();
37  Vec3d(double x, double y,double z);
38  Vec3d(const Vec3d &v2);
39 };
40 
41 std::ostream& operator<<(std::ostream& os, const Vec3d& v);
42 Vec3d operator+(const Vec3d &left,const Vec3d &right);
43 Vec3d operator-(const Vec3d &left,const Vec3d &right);
44 Vec3d operator-(const Vec3d &v);
45 
46 Vec3d operator*(double left,const Vec3d &right);
47 Vec3d operator*(const Vec3d &left, double right);
48 Vec3d operator*(int left,const Vec3d &right);
49 Vec3d operator*(const Vec3d &left, int right);
50 Vec3d operator/(const Vec3d &left, double right);
51 
52 double operator*(const Vec3d & v1, const Vec3d & v2);
53 Vec3d cross(const Vec3d &v1, const Vec3d &v2);
54 double norm(const Vec3d &v);
55 double dist(const Vec3d &v1, const Vec3d &v2);
56 
57 std::istream& operator>>(std::istream& is, Vec3d &v);
58 
59 
60 
61 #endif
Class to store positions and to handle operations on 3d vectors.
Definition: Vec3d.h:9
double v[3]
Actual vector elements:
Definition: Vec3d.h:13
Vec3d()
Class to store positions and to handle operations on 3d vectors.
Definition: Vec3d.cc:8