OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
Vector3D.h
Go to the documentation of this file.
1 #ifndef CLASSIC_Vector3D_HH
2 #define CLASSIC_Vector3D_HH
3 
4 // ------------------------------------------------------------------------
5 // $RCSfile: Vector3D.h,v $
6 // ------------------------------------------------------------------------
7 // $Revision: 1.1.1.1 $
8 // ------------------------------------------------------------------------
9 // Copyright: see Copyright.readme
10 // ------------------------------------------------------------------------
11 //
12 // Class: Vector3D
13 //
14 // ------------------------------------------------------------------------
15 // Class category: BeamlineGeometry
16 // ------------------------------------------------------------------------
17 //
18 // $Date: 2000/03/27 09:32:34 $
19 // $Author: fci $
20 //
21 // ------------------------------------------------------------------------
22 
23 
24 // Class Vector3D
25 // ------------------------------------------------------------------------
27 // The copy constructor, destructor, and assignment operator generated
28 // by the compiler perform the correct operation. For speed reasons they
29 // are not implemented.
30 
31 class Vector3D {
32 
33 public:
34 
36  // Construct null vector.
37  Vector3D();
38 
40  // Use components (x,y,z).
41  Vector3D(double x, double y, double z);
42 
43  bool operator==(const Vector3D &) const;
44  bool operator!=(const Vector3D &) const;
45 
47  Vector3D &operator+=(const Vector3D &vector);
48 
50  Vector3D &operator-=(const Vector3D &vector);
51 
53  Vector3D &operator*=(double factor);
54 
56  Vector3D operator-() const;
57 
59  // Return a reference to component [b]i[/b].
60  double &operator()(int i);
61 
63  // Return the value of component [b]i[/b].
64  double operator()(int i) const;
65 
67  // Return the components (x,y,z).
68  void getComponents(double &x, double &y, double &z) const;
69 
71  // Return the component [b]x[/b].
72  double getX() const;
73 
75  // Return the component [b]y[/b].
76  double getY() const;
77 
79  // Return the component [b]z[/b].
80  double getZ() const;
81 
83  void clear();
84 
86  bool isZero() const;
87 
89  // Assign the component [b]x[/b].
90  void setX(double);
91 
93  // Assign the component [b]y[/b].
94  void setY(double);
95 
97  // Assign the component [b]z[/b].
98  void setZ(double);
99 
100 protected:
101 
102  // Vector components.
103  double v[3];
104 };
105 
106 
107 // External functions.
108 // ------------------------------------------------------------------------
109 
111 extern Vector3D operator+(const Vector3D &a, const Vector3D &b);
112 
114 extern Vector3D operator-(const Vector3D &a, const Vector3D &b);
115 
117 extern Vector3D operator*(const Vector3D &a, double factor);
118 
120 extern Vector3D operator*(double factor, const Vector3D &a);
121 
123 extern Vector3D cross(const Vector3D &a, const Vector3D &b);
124 
126 extern double dot(const Vector3D &a, const Vector3D &b);
127 
128 
129 // Inline functions.
130 // ------------------------------------------------------------------------
131 
133 { v[0] = v[1] = v[2] = 0.0; }
134 
135 
136 inline double &Vector3D::operator()(int i)
137 { return v[i]; }
138 
139 
140 inline double Vector3D::operator()(int i) const
141 { return v[i]; }
142 
143 
144 inline double Vector3D::getX() const
145 { return v[0]; }
146 
147 
148 inline double Vector3D::getY() const
149 { return v[1]; }
150 
151 
152 inline double Vector3D::getZ() const
153 { return v[2]; }
154 
155 
156 inline void Vector3D::setX(double x)
157 { v[0] = x; }
158 
159 
160 inline void Vector3D::setY(double y)
161 { v[1] = y; }
162 
163 
164 inline void Vector3D::setZ(double z)
165 { v[2] = z; }
166 
167 #endif // CLASSIC_Vector3D_HH
Vector3D cross(const Vector3D &a, const Vector3D &b)
Vector cross product.
Definition: Vector3D.cpp:111
Vector3D operator+(const Vector3D &a, const Vector3D &b)
Add.
Definition: Vector3D.cpp:73
double dot(const Vector3D &a, const Vector3D &b)
Vector dot product.
Definition: Vector3D.cpp:118
Vector3D operator-(const Vector3D &a, const Vector3D &b)
Subtract.
Definition: Vector3D.cpp:78
Vector3D operator*(const Vector3D &a, double factor)
Multiply.
Definition: Vector3D.cpp:83
std::complex< double > a
A 3-dimension vector.
Definition: Vector3D.h:31
void setY(double)
Set component.
Definition: Vector3D.h:160
Vector3D()
Default constructor.
Definition: Vector3D.h:132
bool operator!=(const Vector3D &) const
Definition: Vector3D.cpp:63
void clear()
Set to zero.
Definition: Vector3D.cpp:93
Vector3D & operator-=(const Vector3D &vector)
Subtract and assign.
Definition: Vector3D.cpp:42
void setX(double)
Set component.
Definition: Vector3D.h:156
double getY() const
Get component.
Definition: Vector3D.h:148
Vector3D & operator*=(double factor)
Scale and assign.
Definition: Vector3D.cpp:50
void setZ(double)
Set component.
Definition: Vector3D.h:164
void getComponents(double &x, double &y, double &z) const
Get components.
Definition: Vector3D.cpp:98
double getX() const
Get component.
Definition: Vector3D.h:144
bool operator==(const Vector3D &) const
Definition: Vector3D.cpp:58
Vector3D & operator+=(const Vector3D &vector)
Add and assign.
Definition: Vector3D.cpp:34
bool isZero() const
Test for zero.
Definition: Vector3D.cpp:106
double getZ() const
Get component.
Definition: Vector3D.h:152
double v[3]
Definition: Vector3D.h:103
double & operator()(int i)
Get component.
Definition: Vector3D.h:136
Vector3D operator-() const
Negative vector.
Definition: Vector3D.cpp:68