]> Creatis software - FrontAlgorithms.git/blob - lib/Airways/MathLib/vec3.h
...
[FrontAlgorithms.git] / lib / Airways / MathLib / vec3.h
1 /**
2  * Class that models a vector in 3D
3  * Author: Diego Cáceres
4  * Modifications by: Alfredo Morales Pinzón
5  * Date modifications: Octobre 7, 2014
6  */
7 #ifndef VEC3_H
8 #define VEC3_H
9
10 #include <Airways/MathLib/TempAirwaysAppli_MathLib_Export.h>
11 #include <cmath>
12 #include <iostream>
13 #include <limits>       // std::numeric_limits
14
15 //------------------------------------------------------------------------------
16 /**
17  * @brief The Vec3 class that represents a vector in 3D
18  */
19 class TempAirwaysAppli_MathLib_EXPORT Vec3
20 {
21 private:
22         float x, y, z; //!< Coordinates
23 public:
24         //----------------------------------------------------------------------------
25         /**
26          * @brief Vec3
27          */
28         Vec3();
29         //----------------------------------------------------------------------------
30         /**
31          * @brief Vec3
32          * @param x
33          * @param y
34          * @param z
35          */
36         Vec3(const float& x, const float& y, const float& z);
37         //----------------------------------------------------------------------------
38         //Getters
39         //----------------------------------------------------------------------------
40         /**
41          * @brief GetVec3
42          * @return
43          */
44         const float* GetVec3() const;
45         //----------------------------------------------------------------------------
46         /**
47          * @brief GetVec3
48          * @return
49          */
50         float* GetVec3();
51         //----------------------------------------------------------------------------
52         /**
53          * @brief Norm
54          * @return
55          */
56         float Norm() const;
57
58         /**
59          * Method that normalizes the vector. v = v/|v|
60          */
61         void Normalize();
62
63         /**
64          * Method that sets all the values
65          */
66         void set(const float& x, const float& y, const float& z);
67
68         /**
69          * @brief Dot
70          * @param b
71          * @return
72          */
73         float Dot(const Vec3& b) const;
74         //----------------------------------------------------------------------------
75         /**
76          * @brief Orthogonal
77          * @param b
78          * @return
79          */
80         Vec3 Orthogonal(const Vec3& b) const;
81         //----------------------------------------------------------------------------
82         /**
83          * @brief Cross
84          * @param b
85          * @return
86          */
87         Vec3 Cross(const Vec3& b) const;
88         //----------------------------------------------------------------------------
89         /**
90          * @brief EculideanDistance between two points
91          * @param b
92          * @return
93          */
94         float EculideanDistance(const Vec3& b) const;
95         //----------------------------------------------------------------------------
96         //Operator Overloads
97         //----------------------------------------------------------------------------
98         /**
99          * @brief The copy operator
100          * @param vec
101          * @return
102          */
103         Vec3& operator=(const Vec3& vec);
104         //----------------------------------------------------------------------------
105         /**
106          * @brief operator []
107          * @param i
108          * @return
109          */
110         float& operator[](unsigned int i);
111         //----------------------------------------------------------------------------
112         /**
113          * @brief operator []
114          * @param i
115          * @return
116          */
117         const float& operator[](unsigned int i) const;
118         //----------------------------------------------------------------------------
119         /**
120          * @brief operator +
121          * @return
122          */
123         Vec3 operator+() const;
124         //----------------------------------------------------------------------------
125         /**
126          * @brief operator -
127          * @return
128          */
129         Vec3 operator-() const;
130         //----------------------------------------------------------------------------
131         /**
132          * @brief operator +=
133          * @param b
134          * @return
135          */
136         Vec3& operator+=(const Vec3& b);
137         //----------------------------------------------------------------------------
138         /**
139          * @brief operator -=
140          * @param b
141          * @return
142          */
143         Vec3& operator-=(const Vec3& b);
144         //----------------------------------------------------------------------------
145         /**
146          * @brief operator *=
147          * @param k
148          * @return
149          */
150         Vec3& operator*=(const float& k);
151         //----------------------------------------------------------------------------
152         /**
153          * @brief operator /=
154          * @param k
155          * @return
156          */
157         Vec3& operator/=(const float& k);
158         //----------------------------------------------------------------------------
159         /**
160          * @brief operator +
161          * @param b
162          * @return
163          */
164         Vec3 operator+(const Vec3& b);
165         //----------------------------------------------------------------------------
166         /**
167          * @brief operator -
168          * @param b
169          * @return
170          */
171         Vec3 operator-(const Vec3& b);
172         //----------------------------------------------------------------------------
173         /**
174          * @brief operator *
175          * @param k
176          * @return
177          */
178         Vec3 operator*(const float& k);
179         //----------------------------------------------------------------------------
180         /**
181          * @brief operator /
182          * @param k
183          * @return
184          */
185         Vec3 operator/(const float& k);
186         //----------------------------------------------------------------------------
187         /**
188          * @brief operator ==
189          * @param b
190          * @return
191          */
192         bool operator==(const Vec3& b) const;
193         //----------------------------------------------------------------------------
194         /**
195          * @brief operator !=
196          * @param b
197          * @return
198          */
199         bool operator!=(const Vec3& b) const;
200         //----------------------------------------------------------------------------
201         /**
202          * @brief operator <
203          * @param b
204          * @return
205          */
206         bool operator<(const Vec3& b) const;
207         //----------------------------------------------------------------------------
208         /**
209          * @brief operator >
210          * @param b
211          * @return
212          */
213         bool operator>(const Vec3& b);
214         //----------------------------------------------------------------------------
215         friend std::ostream& operator<<(std::ostream& os, const Vec3& coord);
216         //----------------------------------------------------------------------------
217
218 };
219 //------------------------------------------------------------------------------
220
221 #endif // VEC3_H