/home/damien/work/2012_2013_teaching/2012_5eti_synthese/lib3d/v4.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 V4_HPP
22 #define V4_HPP
23 
24 #include <string>
25 #include <iostream>
26 
27 #include <exception_cpe.hpp>
28 
29 namespace cpe
30 {
31 class v3;
32 class v2;
33 
35 class v4
36 {
37 public:
38 
39  // ********************************************* //
40  // ********************************************* //
41  // CONSTRUCTORS
42  // ********************************************* //
43  // ********************************************* //
44 
46  v4();
48  v4(const double& x,const double& y,const double& z,const double& w);
49 
50  // ********************************************* //
51  // ********************************************* //
52  // Get/set
53  // ********************************************* //
54  // ********************************************* //
55 
57  const double& x() const;
59  double& x();
61  const double& y() const;
63  double& y();
65  const double& z() const;
67  double& z();
69  const double& w() const;
71  double& w();
72 
74  const double& operator[](const size_t& k) const;
76  double& operator[](const size_t& k);
78  const double& operator()(const size_t& k) const;
80  double& operator()(const size_t& k);
81 
83  void set_zero();
84 
85  // ********************************************* //
86  // ********************************************* //
87  // Convert to lower dimension
88  // ********************************************* //
89  // ********************************************* //
90 
92  v3 to_v3() const;
94  v2 to_v2() const;
95 
96 
97 
98  // ********************************************* //
99  // ********************************************* //
100  // Math operation
101  // ********************************************* //
102  // ********************************************* //
103 
105  double dot(const v4& p) const;
106 
108  double norm() const;
110  double norm2() const;
112  v4 normalized() const;
113 
114 
115 
116 
117 
118 
119  // ********************************************* //
120  // ********************************************* //
121  // Operator +-*/
122  // ********************************************* //
123  // ********************************************* //
124 
126  v4 operator+(const v4& p2) const;
128  v4 operator+(const double& s) const;
129 
131  v4 operator-(const v4& p2) const;
133  v4 operator-(const double& s) const;
134 
136  v4 operator*(const double& s) const;
138  v4 operator/(const double& s) const;
139 
141  v4& operator+=(const v4& p);
143  v4& operator+=(const double& s);
145  v4& operator-=(const v4& p);
147  v4& operator-=(const double& s);
149  v4& operator*=(const double& s);
151  v4& operator/=(const double& s);
152 
154  v4 operator-() const;
155 
159  v4 product_compontentwise(const v4& p) const;
166  void scale(const double& sx,const double& sy,const double& sz,const double& sw);
167 
168 
169  // ********************************************* //
170  // ********************************************* //
171  // Output
172  // ********************************************* //
173  // ********************************************* //
174 
176  std::string to_string() const;
177 
178 
179 
180 private:
181 
182 
183  // ********************************************* //
184  // ********************************************* //
185  // Internal parameters
186  // ********************************************* //
187  // ********************************************* //
188 
190  double internal_x;
192  double internal_y;
194  double internal_z;
196  double internal_w;
197 
198 
199  // ********************************************* //
200  // ********************************************* //
201  // Helper
202  // ********************************************* //
203  // ********************************************* //
204 
206  void assert_size(const size_t& k) const;
207 
208 };
209 
211 v4 operator+(const double& s,const v4& p);
213 v4 operator-(const double& s,const v4& p);
215 v4 operator*(const double& s,const v4& p);
216 
217 // ********************************************* //
218 // ********************************************* //
219 // Output
220 // ********************************************* //
221 // ********************************************* //
222 
224 std::ostream& operator<<(std::ostream& stream,const v4& p);
225 
228 {
229 public:
230 
234  exception_v4(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
235 };
236 
237 }
238 
239 
240 
241 #endif