scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
vector_unit_3d.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_UNITS_VECTOR_UNIT_3D_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_VECTOR_UNIT_3D_HPP_INCLUDED
3
4#include "./scalar_unit.hpp"
7#include "../meca_number/angle.hpp"
8#include "../util/is_number.hpp"
9#include "../coordinates/direction.hpp"
10
11#include "boost/algorithm/string.hpp"
12
13#include <cmath>
14#include <functional>
15#include <iostream>
16#include <list>
17#include <sstream>
18#include <string>
19#include <vector>
20
21#define VECTOR_UNIT_3D_HPP_BEGIN(name) class name##_3d : public vector_unit_3d \
22 { \
23 public: \
24 name##_3d(); \
25 name##_3d(const name##_3d&); \
26 name##_3d(name##_3d&&); \
27 explicit name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi,dimension::position new_position = dimension::NUMERATOR); \
28 explicit name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
29 explicit name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
30 explicit name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
31 explicit name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
32 explicit name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
33 explicit name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
34 explicit name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
35 explicit name##_3d(float new_value,const string& init_dimensions,float new_theta,float new_phi); \
36 explicit name##_3d(float new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
37 explicit name##_3d(double new_value,const string& init_dimensions,float new_theta,float new_phi); \
38 explicit name##_3d(double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
39 explicit name##_3d(long double new_value,const string& init_dimensions,float new_theta,float new_phi); \
40 explicit name##_3d(long double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
41 explicit name##_3d(int new_value,const string& init_dimensions,float new_theta,float new_phi); \
42 explicit name##_3d(int new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
43 explicit name##_3d(float new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
44 explicit name##_3d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
45 explicit name##_3d(double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
46 explicit name##_3d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
47 explicit name##_3d(long double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
48 explicit name##_3d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
49 explicit name##_3d(int new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
50 explicit name##_3d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
51 explicit name##_3d(const scalar_unit& x,float new_theta,float new_phi); \
52 explicit name##_3d(const scalar_unit& x,const angle& new_theta,const angle& new_phi); \
53 explicit name##_3d(const string& init_scalar,float new_theta,float new_phi); \
54 explicit name##_3d(const string& init_scalar,const angle& new_theta,const angle& new_phi); \
55 explicit name##_3d(const string& init_vector_3d); \
56 explicit name##_3d(const vector_unit_3d& init_vector_3d); \
57 explicit name##_3d(vector_unit_3d&& init_vector_3d); \
58 name##_3d& operator =(const name##_3d& x); \
59 name##_3d& operator =(name##_3d&& x); \
60 using vector_unit_3d::operator =; \
61 using vector_unit_3d::operator+=; \
62 using vector_unit_3d::operator-=
63
64#define VECTOR_UNIT_3D_HPP_END() public: \
65 static const string dimensions_match; \
66 static const vector<dimension> real_dimensions; \
67 }
68
69#define VECTOR_UNIT_3D_HPP(name) class name##_3d : public vector_unit_3d \
70 { \
71 public: \
72 name##_3d(); \
73 name##_3d(const name##_3d&); \
74 name##_3d(name##_3d&&); \
75 explicit name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi,dimension::position new_position = dimension::NUMERATOR); \
76 explicit name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
77 explicit name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
78 explicit name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
79 explicit name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
80 explicit name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
81 explicit name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position = dimension::NUMERATOR); \
82 explicit name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position = dimension::NUMERATOR); \
83 explicit name##_3d(float new_value,const string& init_dimensions,float new_theta,float new_phi); \
84 explicit name##_3d(float new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
85 explicit name##_3d(double new_value,const string& init_dimensions,float new_theta,float new_phi); \
86 explicit name##_3d(double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
87 explicit name##_3d(long double new_value,const string& init_dimensions,float new_theta,float new_phi); \
88 explicit name##_3d(long double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
89 explicit name##_3d(int new_value,const string& init_dimensions,float new_theta,float new_phi); \
90 explicit name##_3d(int new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi); \
91 explicit name##_3d(float new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
92 explicit name##_3d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
93 explicit name##_3d(double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
94 explicit name##_3d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
95 explicit name##_3d(long double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
96 explicit name##_3d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
97 explicit name##_3d(int new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi); \
98 explicit name##_3d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi); \
99 explicit name##_3d(const scalar_unit& x,float new_theta,float new_phi); \
100 explicit name##_3d(const scalar_unit& x,const angle& new_theta,const angle& new_phi); \
101 explicit name##_3d(const string& init_scalar,float new_theta,float new_phi); \
102 explicit name##_3d(const string& init_scalar,const angle& new_theta,const angle& new_phi); \
103 explicit name##_3d(const string& init_vector_3d); \
104 explicit name##_3d(const vector_unit_3d& init_vector_3d); \
105 explicit name##_3d(vector_unit_3d&& init_vector_3d); \
106 name##_3d& operator =(const name##_3d& x); \
107 name##_3d& operator =(name##_3d&& x); \
108 using vector_unit_3d::operator =; \
109 using vector_unit_3d::operator+=; \
110 using vector_unit_3d::operator-=; \
111\
112 static const string dimensions_match; \
113 static const vector<dimension> real_dimensions; \
114 }
115
116#define VECTOR_UNIT_3D_CPP(name,init_real_dimensions) name##_3d::name##_3d() : vector_unit_3d() {} \
117 name##_3d::name##_3d(const name##_3d& x) : vector_unit_3d(x) {} \
118 name##_3d::name##_3d(name##_3d&& x) : vector_unit_3d(std::move(x)) {} \
119 name##_3d::name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
120 { \
121 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
122 } \
123\
124 name##_3d::name##_3d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
125 { \
126 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
127 } \
128\
129 name##_3d::name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
130 { \
131 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
132 } \
133\
134 name##_3d::name##_3d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
135 { \
136 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
137 } \
138\
139 name##_3d::name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
140 { \
141 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
142 } \
143\
144 name##_3d::name##_3d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
145 { \
146 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
147 } \
148\
149 name##_3d::name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, float new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_position) \
150 { \
151 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
152 } \
153\
154 name##_3d::name##_3d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, const angle& new_phi, dimension::position new_position) : vector_unit_3d(new_value,new_dimension,new_prefix,new_theta,new_phi,new_position) \
155 { \
156 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
157 } \
158\
159 name##_3d::name##_3d(float new_value,const string& init_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
160 { \
161 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
162 } \
163\
164 name##_3d::name##_3d(float new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
165 { \
166 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
167 } \
168\
169 name##_3d::name##_3d(double new_value,const string& init_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
170 { \
171 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
172 } \
173\
174 name##_3d::name##_3d(double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
175 { \
176 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
177 } \
178\
179 name##_3d::name##_3d(long double new_value,const string& init_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
180 { \
181 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
182 } \
183\
184 name##_3d::name##_3d(long double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
185 { \
186 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
187 } \
188\
189 name##_3d::name##_3d(int new_value,const string& init_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
190 { \
191 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
192 } \
193\
194 name##_3d::name##_3d(int new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,init_dimensions,new_theta,new_phi) \
195 { \
196 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
197 } \
198\
199 name##_3d::name##_3d(float new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
200 { \
201 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
202 } \
203\
204 name##_3d::name##_3d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
205 { \
206 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
207 } \
208\
209 name##_3d::name##_3d(double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
210 { \
211 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
212 } \
213\
214 name##_3d::name##_3d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
215 { \
216 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
217 } \
218\
219 name##_3d::name##_3d(long double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
220 { \
221 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
222 } \
223\
224 name##_3d::name##_3d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
225 { \
226 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
227 } \
228\
229 name##_3d::name##_3d(int new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
230 { \
231 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
232 } \
233\
234 name##_3d::name##_3d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi) : vector_unit_3d(new_value,new_dimensions,new_theta,new_phi) \
235 { \
236 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
237 } \
238\
239 name##_3d::name##_3d(const scalar_unit& x,float new_theta,float new_phi) : vector_unit_3d(x,new_theta,new_phi) \
240 { \
241 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
242 } \
243\
244 name##_3d::name##_3d(const scalar_unit& x,const angle& new_theta,const angle& new_phi) : vector_unit_3d(x,new_theta,new_phi) \
245 { \
246 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
247 } \
248\
249 name##_3d::name##_3d(const string& init_scalar,float new_theta,float new_phi) : vector_unit_3d(init_scalar,new_theta,new_phi) \
250 { \
251 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
252 } \
253\
254 name##_3d::name##_3d(const string& init_scalar,const angle& new_theta,const angle& new_phi) : vector_unit_3d(init_scalar,new_theta,new_phi) \
255 { \
256 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
257 } \
258\
259 name##_3d::name##_3d(const string& init_vector_3d) : vector_unit_3d() \
260 { \
261 vector_unit_3d::initialize_from_string(init_vector_3d); \
262 } \
263\
264 name##_3d::name##_3d(const vector_unit_3d& x) : vector_unit_3d(x) \
265 { \
266 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
267 } \
268\
269 name##_3d::name##_3d(vector_unit_3d&& x) : vector_unit_3d(x) \
270 { \
271 scalar_unit::check_dimensions(name##_3d::real_dimensions); \
272 } \
273\
274 name##_3d& name##_3d::operator =(const name##_3d& x) \
275 { \
276 vector_unit_3d::operator =(x); \
277 return *this; \
278 } \
279\
280 name##_3d& name##_3d::operator =(name##_3d&& x) \
281 { \
282 vector_unit_3d::operator =(std::move(x)); \
283 return *this; \
284 } \
285const string name##_3d::dimensions_match = init_real_dimensions; \
286const vector<dimension> name##_3d::real_dimensions = create_base_dimensions(init_real_dimensions)
287
288#define VECTOR_UNIT_HPP(name) SCALAR_UNIT_HPP(name); \
289VECTOR_UNIT_2D_HPP(name); \
290VECTOR_UNIT_3D_HPP(name); \
291VECTOR_UNIT_ND_HPP(name)
292
293#define VECTOR_UNIT_CPP(name,init_real_dimensions) SCALAR_UNIT_CPP(name,init_real_dimensions); \
294VECTOR_UNIT_2D_CPP(name,init_real_dimensions); \
295VECTOR_UNIT_3D_CPP(name,init_real_dimensions); \
296VECTOR_UNIT_ND_CPP(name,init_real_dimensions)
297
298using namespace std;
299
300namespace scifir
301{
303 {
304 public:
316 explicit vector_unit_3d(float new_value,const string& init_dimensions,float new_theta,float new_phi);
317 explicit vector_unit_3d(float new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi);
318 explicit vector_unit_3d(double new_value,const string& init_dimensions,float new_theta,float new_phi);
319 explicit vector_unit_3d(double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi);
320 explicit vector_unit_3d(long double new_value,const string& init_dimensions,float new_theta,float new_phi);
321 explicit vector_unit_3d(long double new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi);
322 explicit vector_unit_3d(int new_value,const string& init_dimensions,float new_theta,float new_phi);
323 explicit vector_unit_3d(int new_value,const string& init_dimensions,const angle& new_theta,const angle& new_phi);
326 explicit vector_unit_3d(double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi);
328 explicit vector_unit_3d(long double new_value,const vector<dimension>& new_dimensions,float new_theta,float new_phi);
329 explicit vector_unit_3d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta,const angle& new_phi);
332 explicit vector_unit_3d(const scalar_unit& x,float new_theta,float new_phi);
333 explicit vector_unit_3d(const scalar_unit& x,const angle& new_theta,const angle& new_phi);
334 explicit vector_unit_3d(const string& init_scalar,float new_theta,float new_phi);
335 explicit vector_unit_3d(const string& init_scalar,const angle& new_theta,const angle& new_phi);
336 explicit vector_unit_3d(const string& init_vector_3d);
337
338 static vector_unit_3d cartesian_3d(const string& init_dimensions,float new_x,float new_y,float new_z)
339 {
340 float new_value = float(std::sqrt(std::pow(new_x,2) + std::pow(new_y,2) + std::pow(new_z,2)));
344 }
345
347 {
348 float new_value = float(std::sqrt(std::pow(new_p,2) + std::pow(new_z,2)));
351 }
352
358
359 bool operator ==(vector_unit_3d x) const;
360
362
363 void operator +=(const vector_unit_3d& x);
365
368
369 vector_unit_3d operator *(const scalar_unit& x) const;
370 vector_unit_3d operator /(const scalar_unit& x) const;
371 vector_unit_3d operator ^(const scalar_unit& x) const;
372
375 {
376 vector_unit_3d y = *this;
377 y += x;
378 return y;
379 }
380
383 {
384 vector_unit_3d y = *this;
385 y -= x;
386 return y;
387 }
388
391 {
392 vector_unit_3d y = *this;
393 y *= x;
394 return y;
395 }
396
399 {
400 vector_unit_3d y = *this;
401 y /= x;
402 return y;
403 }
404
407 {
409 }
410
413 {
415 }
416
419 {
421 }
422
425 {
426 scalar_unit::value *= std::abs(x);
427 if(x < 0)
428 {
429 invert();
430 }
431 }
432
435 {
436 scalar_unit::value /= std::abs(x);
437 if(x < 0)
438 {
439 invert();
440 }
441 }
442
447
452
457
458 inline void invert()
459 {
460 theta.invert();
461 phi = 180.0f - phi;
462 }
463
467
470
471 protected:
473 };
474
475 string to_string(const vector_unit_3d& x);
478 vector_unit_3d sqrt_nth(const vector_unit_3d& x,int index);
482 bool same_direction(const vector_unit_3d& x,const vector_unit_3d& y);
483 bool parallel(const vector_unit_3d& x,const vector_unit_3d& y);
484 bool orthogonal(const vector_unit_3d& x,const vector_unit_3d& y);
485}
486
488
489template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
491{
493 z += y;
494 return z;
495}
496
497template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
502
503template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
505{
507 z *= y;
508 return z;
509}
510
511template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
513{
514 vector<scifir::dimension> new_dimensions = x.get_dimensions();
515 for (scifir::dimension& new_dimension : new_dimensions)
516 {
517 new_dimension.invert();
518 }
519 return scifir::vector_unit_3d(y / x.get_value(),new_dimensions,x.theta,x.phi);
520}
521
523
524bool operator ==(const scifir::vector_unit_3d& x, const string& init_vector_3d);
525bool operator !=(const scifir::vector_unit_3d& x, const string& init_vector_3d);
526bool operator ==(const string& init_vector_3d, const scifir::vector_unit_3d& x);
527bool operator !=(const string& init_vector_3d, const scifir::vector_unit_3d& x);
528
529void operator +=(string& x, const scifir::vector_unit_3d& y);
530string operator +(const string& x, const scifir::vector_unit_3d& y);
531string operator +(const scifir::vector_unit_3d& y, const string& x);
532
533ostream& operator <<(ostream& os, const scifir::vector_unit_3d& x);
534istream& operator >>(istream& is, scifir::vector_unit_3d& x);
535
536#endif // SCIFIR_UNITS_UNITS_VECTOR_UNIT_3D_HPP_INCLUDED
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77
void invert()
Inverts the angle to the opposite direction in a 2D plane, which is to add 180 degrees....
Definition angle.cpp:250
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
Definition dimension.hpp:34
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Definition prefix.hpp:16
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
float value
Value of the scalar_unit. It changes automatically when the dimensions change.
scalar_unit()
Default constructor, the value is 0 and the dimensions are empty.
const float & get_value() const
Read-only getter of the value.
Class that creates a vector unit in 3D. The vector is in spherical coordinates with a value and dimen...
void operator+=(const vector_unit_3d &x)
The vector_unit_3d is summed as vector, in spherical coordinates. The addition of vectors is used for...
void operator-=(vector_unit_3d x)
The vector_unit_3d is substracted as vector, in spherical coordinates. The substraction of vectors is...
vector_unit_3d operator/(const scalar_unit &x) const
It creates a new vector_unit_3d scaling a vector_unit_3d by the inverse of the scalar_unit x.
void invert()
Changes the direction of the vector to the opposite direction. It does that by adding 180 degrees to ...
scalar_unit y_projection() const
It creates the y projection of the vector, returning it as a scalar_unit of the same dimensions,...
void initialize_from_string(string init_vector_3d)
Initializes the member-variables with the initialization string of vector_unit_3d init_vector_3d.
void point_to(direction::name x)
Theta is set to the direction specified in 3D. Possible values are LEFT, RIGHT, TOP,...
vector_unit_3d operator^(const scalar_unit &x) const
It powers a vector by a scalar_unit x if that scalar_unit has empty dimensions.
scalar_unit z_projection() const
It creates the z projection of the vector, returning it as a scalar_unit of the same dimensions,...
string vectorial_custom_display(const string &init_dimensions, int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also the angle theta and t...
scalar_unit x_projection() const
It creates the x projection of the vector, returning it as a scalar_unit of the same dimensions,...
string vectorial_base_display(int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also the angle theta and t...
void operator/=(T x)
It divides the numeric type x to the value. Theta and phi are not changed.
vector_unit_3d & operator=(const vector_unit_3d &x)
Copy assignment. The member-variables are copied from the vector_unit_3d x.
vector_unit_3d()
Default constructor. The value is set to 0, the dimensions are empty and theta and phi are 0.
angle theta
Angle theta of the vector in 3D space, in spherical coordinates. As all angles of scifir-units,...
vector_unit_3d operator-(vector_unit_3d x) const
Substraction of vectors in 3D. It creates a new vector as the difference of the other two.
void operator*=(T x)
It multiplies the numeric type x to the value. Theta and phi are not changed.
bool operator==(vector_unit_3d x) const
Comparison operator. Two vector_unit_3d are equal if their value, dimensions, theta and phi are the s...
vector_unit_3d operator+(const vector_unit_3d &x) const
Addition of vectors in 3D. It creates a new vector as the addition of the other two.
string vectorial_display(int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also the angle theta and t...
vector_unit_3d operator*(const scalar_unit &x) const
It creates a new vector_unit_3d scaling a vector_unit_3d by the scalar_unit x.
static vector_unit_3d cartesian_3d(const string &init_dimensions, float new_x, float new_y, float new_z)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
angle phi
Angle phi of the vector in 3D space, in spherical coordinates. As all angles of scifir-units,...
static vector_unit_3d cylindrical(const string &init_dimensions, float new_p, angle new_theta, float new_z)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
angle angle_between(const vector_unit_2d &x, const vector_unit_2d &y)
Returns the angle between two vectors x and y inside a 2D space.
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
Definition angle.cpp:421
bool same_direction(const vector_unit_2d &x, const vector_unit_2d &y)
Checks if two vectors x and y have the same direction.
float cos(const angle &x)
Calculates the cos of angle x. It uses the cos() function of the standard library of C++,...
Definition angle.cpp:431
bool orthogonal(const angle &x, const angle &y)
Checks if two angles in a 2D correspond to orthogonal lines (or orthogonal vectors).
Definition angle.cpp:403
float atan_degree(float x)
Calculates the atan receiving x in degrees. It uses the atan() function of the standard library of C+...
Definition angle.hpp:252
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
float acos_degree(float x)
Calculates the acos receiving x in degrees. It uses the acos() function of the standard library of C+...
Definition angle.hpp:247
scalar_unit dot_product(const vector_unit_2d &x, const vector_unit_2d &y)
Creates a scalar_unit as the dot product of the two vectors x and y.
vector_unit_3d cross_product(const vector_unit_3d &x, const vector_unit_3d &y)
Creates a vector_unit_3d as the cross product of the two vectors x and y.
scalar_unit norm(const vector_unit_2d &x)
It returns the value of the vector in polar coordinates, p.
float sin(const angle &x)
Calculates the sin of angle x. It uses the sin() function of the standard library of C++,...
Definition angle.cpp:426
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416
bool parallel(const angle &x, const angle &y)
Checks if two angles in a 2D correspond to parallel lines (or parallel vectors).
Definition angle.cpp:391
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.
scifir::vector_unit_3d operator-(const T y, const scifir::vector_unit_3d &x)
It creates a new vector as the substraction of the numeric type x with the value. Theta and phi are n...
scifir::vector_unit_3d operator+(const T y, const scifir::vector_unit_3d &x)
It creates a new vector as the addition of the numeric type x to the value. Theta and phi are not cha...
bool operator==(const scifir::vector_unit_3d &x, const string &init_vector_3d)
Returns true if x is equal to the vector_unit_3d initialized with the string being compared....
scifir::vector_unit_3d operator*(const scifir::scalar_unit &x, const scifir::vector_unit_3d &y)
It creates a new vector_unit_3d scaling a vector_unit_3d by the scalar_unit x.
scifir::vector_unit_3d operator/(const T y, const scifir::vector_unit_3d &x)
It creates a new vector as the division of the numeric type x with the value. Theta and phi are not c...
istream & operator>>(istream &is, scifir::vector_unit_3d &x)
Allows that an istream initializes by string a vector_unit_3d x.
ostream & operator<<(ostream &os, const scifir::vector_unit_3d &x)
Adds the string representation of the vector_unit_3d x to an output stream os.
bool operator!=(const scifir::vector_unit_3d &x, const scifir::vector_unit_3d &y)
Comparison operator. Two vector_unit_3d are not equal if their value, dimensions, theta or phi are di...
void operator+=(string &x, const scifir::vector_unit_3d &y)
Concatenates the string representation of the vector_unit_3d y to the string x.