/home/damien/work/2012_2013_teaching/2012_5eti_synthese/lib3d/v3.hpp
Go to the documentation of this file.
1 /*
2 ** TP 5ETI CPE Lyon
3 ** Copyright (C) 2012 Damien Rohmer
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 
21 #ifndef V3_HPP
22 #define V3_HPP
23 
24 #include <string>
25 #include <iostream>
26 
27 #include <exception_cpe.hpp>
28 
29 namespace cpe
30 {
31 class v2;
32 
34 class v3
35 {
36 public:
37 
38  // ********************************************* //
39  // ********************************************* //
40  // CONSTRUCTORS
41  // ********************************************* //
42  // ********************************************* //
43 
45  v3();
47  v3(const double& x,const double& y,const double& z);
48 
49  // ********************************************* //
50  // ********************************************* //
51  // Get/set
52  // ********************************************* //
53  // ********************************************* //
54 
56  const double& x() const;
58  double& x();
60  const double& y() const;
62  double& y();
64  const double& z() const;
66  double& z();
67 
69  const double& operator[](const size_t& k) const;
71  double& operator[](const size_t& k);
73  const double& operator()(const size_t& k) const;
75  double& operator()(const size_t& k);
76 
78  void set_zero();
79 
80  // ********************************************* //
81  // ********************************************* //
82  // Convert to lower dimension
83  // ********************************************* //
84  // ********************************************* //
85 
87  v2 to_v2() const;
88 
89 
90  // ********************************************* //
91  // ********************************************* //
92  // Math operation
93  // ********************************************* //
94  // ********************************************* //
95 
97  double dot(const v3& p) const;
98 
100  double norm() const;
102  double norm2() const;
104  v3 normalized() const;
105 
107  v3 cross(const v3& p) const;
108 
109 
110 
111 
112  // ********************************************* //
113  // ********************************************* //
114  // Operator +-*/
115  // ********************************************* //
116  // ********************************************* //
117 
119  v3 operator+(const v3& p2) const;
121  v3 operator+(const double& s) const;
122 
124  v3 operator-(const v3& p2) const;
126  v3 operator-(const double& s) const;
127 
128 
130  v3 operator*(const double& s) const;
132  v3 operator/(const double& s) const;
133 
135  v3& operator+=(const v3& p);
137  v3& operator+=(const double& s);
139  v3& operator-=(const v3& p);
141  v3& operator-=(const double& s);
143  v3& operator*=(const double& s);
145  v3& operator/=(const double& s);
146 
148  v3 operator-() const;
149 
153  v3 product_compontentwise(const v3& p) const;
160  void scale(const double& sx,const double& sy,const double& sz);
161 
162 
163  // ********************************************* //
164  // ********************************************* //
165  // Output
166  // ********************************************* //
167  // ********************************************* //
168 
170  std::string to_string() const;
171 
172 
173 
174 private:
175 
176 
177  // ********************************************* //
178  // ********************************************* //
179  // Internal parameters
180  // ********************************************* //
181  // ********************************************* //
182 
184  double internal_x;
186  double internal_y;
188  double internal_z;
189 
190 
191  // ********************************************* //
192  // ********************************************* //
193  // Helper
194  // ********************************************* //
195  // ********************************************* //
196 
198  void assert_size(const size_t& k) const;
199 
200 };
201 
203 v3 operator+(const double& s,const v3& p);
205 v3 operator-(const double& s,const v3& p);
207 v3 operator*(const double& s,const v3& p);
208 
209 // ********************************************* //
210 // ********************************************* //
211 // Output
212 // ********************************************* //
213 // ********************************************* //
214 
216 std::ostream& operator<<(std::ostream& stream,const v3& p);
217 
220 {
221 public:
222 
226  exception_v3(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
227 };
228 
229 }
230 
231 
232 
233 #endif