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_2d.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_UNITS_VECTOR_UNIT_2D_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_VECTOR_UNIT_2D_HPP_INCLUDED
3
4#include "./scalar_unit.hpp"
5#include "../meca_number/angle.hpp"
6#include "../util/is_number.hpp"
7#include "../coordinates/direction.hpp"
8
9#include "boost/algorithm/string.hpp"
10
11#include <iostream>
12#include <string>
13
14#define VECTOR_UNIT_2D_HPP_BEGIN(name) class name##_2d : public vector_unit_2d \
15 { \
16 public: \
17 name##_2d(); \
18 name##_2d(const name##_2d&); \
19 name##_2d(name##_2d&&); \
20 explicit name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta,dimension::position new_position = dimension::NUMERATOR); \
21 explicit name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
22 explicit name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
23 explicit name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
24 explicit name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
25 explicit name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
26 explicit name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
27 explicit name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
28 explicit name##_2d(float new_value,const string& init_dimensions,float new_theta); \
29 explicit name##_2d(float new_value,const string& init_dimensions,const angle& new_theta); \
30 explicit name##_2d(double new_value,const string& init_dimensions,float new_theta); \
31 explicit name##_2d(double new_value,const string& init_dimensions,const angle& new_theta); \
32 explicit name##_2d(long double new_value,const string& init_dimensions,float new_theta); \
33 explicit name##_2d(long double new_value,const string& init_dimensions,const angle& new_theta); \
34 explicit name##_2d(int new_value,const string& init_dimensions,float new_theta); \
35 explicit name##_2d(int new_value,const string& init_dimensions,const angle& new_theta); \
36 explicit name##_2d(float new_value,const vector<dimension>& new_dimensions,float new_theta); \
37 explicit name##_2d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
38 explicit name##_2d(double new_value,const vector<dimension>& new_dimensions,float new_theta); \
39 explicit name##_2d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
40 explicit name##_2d(long double new_value,const vector<dimension>& new_dimensions,float new_theta); \
41 explicit name##_2d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
42 explicit name##_2d(int new_value,const vector<dimension>& new_dimensions,float new_theta); \
43 explicit name##_2d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
44 explicit name##_2d(const scalar_unit& x,float new_theta); \
45 explicit name##_2d(const scalar_unit& x,const angle& new_theta); \
46 explicit name##_2d(const string& init_scalar,float new_theta); \
47 explicit name##_2d(const string& init_scalar,const angle& new_theta); \
48 explicit name##_2d(const string& init_vector_2d); \
49 explicit name##_2d(const vector_unit_2d& x); \
50 explicit name##_2d(vector_unit_2d&& x); \
51 name##_2d& operator =(const name##_2d& x); \
52 name##_2d& operator =(name##_2d&& x); \
53 using vector_unit_2d::operator =; \
54 using vector_unit_2d::operator+=; \
55 using vector_unit_2d::operator-=
56
57#define VECTOR_UNIT_2D_HPP_END() public: \
58 static const string dimensions_match; \
59 static const vector<dimension> real_dimensions; \
60 }
61
62#define VECTOR_UNIT_2D_HPP(name) class name##_2d : public vector_unit_2d \
63 { \
64 public: \
65 name##_2d(); \
66 name##_2d(const name##_2d&); \
67 name##_2d(name##_2d&&); \
68 explicit name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta,dimension::position new_position = dimension::NUMERATOR); \
69 explicit name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
70 explicit name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
71 explicit name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
72 explicit name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
73 explicit name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
74 explicit name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position = dimension::NUMERATOR); \
75 explicit name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position = dimension::NUMERATOR); \
76 explicit name##_2d(float new_value,const string& init_dimensions,float new_theta); \
77 explicit name##_2d(float new_value,const string& init_dimensions,const angle& new_theta); \
78 explicit name##_2d(double new_value,const string& init_dimensions,float new_theta); \
79 explicit name##_2d(double new_value,const string& init_dimensions,const angle& new_theta); \
80 explicit name##_2d(long double new_value,const string& init_dimensions,float new_theta); \
81 explicit name##_2d(long double new_value,const string& init_dimensions,const angle& new_theta); \
82 explicit name##_2d(int new_value,const string& init_dimensions,float new_theta); \
83 explicit name##_2d(int new_value,const string& init_dimensions,const angle& new_theta); \
84 explicit name##_2d(float new_value,const vector<dimension>& new_dimensions,float new_theta); \
85 explicit name##_2d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
86 explicit name##_2d(double new_value,const vector<dimension>& new_dimensions,float new_theta); \
87 explicit name##_2d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
88 explicit name##_2d(long double new_value,const vector<dimension>& new_dimensions,float new_theta); \
89 explicit name##_2d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
90 explicit name##_2d(int new_value,const vector<dimension>& new_dimensions,float new_theta); \
91 explicit name##_2d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta); \
92 explicit name##_2d(const scalar_unit& x,float new_theta); \
93 explicit name##_2d(const scalar_unit& x,const angle& new_theta); \
94 explicit name##_2d(const string& init_scalar,float new_theta); \
95 explicit name##_2d(const string& init_scalar,const angle& new_theta); \
96 explicit name##_2d(const string& init_vector_2d); \
97 explicit name##_2d(const vector_unit_2d& x); \
98 explicit name##_2d(vector_unit_2d&& x); \
99 name##_2d& operator =(const name##_2d& x); \
100 name##_2d& operator =(name##_2d&& x); \
101 using vector_unit_2d::operator =; \
102 using vector_unit_2d::operator+=; \
103 using vector_unit_2d::operator-=; \
104\
105 static const string dimensions_match; \
106 static const vector<dimension> real_dimensions; \
107 }
108
109#define VECTOR_UNIT_2D_CPP(name,init_real_dimensions) name##_2d::name##_2d() : vector_unit_2d() {} \
110 name##_2d::name##_2d(const name##_2d& x) : vector_unit_2d(x) {} \
111 name##_2d::name##_2d(name##_2d&& x) : vector_unit_2d(std::move(x)) {} \
112 name##_2d::name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
113 { \
114 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
115 } \
116\
117 name##_2d::name##_2d(float new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
118 { \
119 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
120 } \
121\
122 name##_2d::name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
123 { \
124 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
125 } \
126\
127 name##_2d::name##_2d(double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
128 { \
129 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
130 } \
131\
132 name##_2d::name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
133 { \
134 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
135 } \
136\
137 name##_2d::name##_2d(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
138 { \
139 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
140 } \
141\
142 name##_2d::name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, float new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
143 { \
144 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
145 } \
146\
147 name##_2d::name##_2d(int new_value, dimension::type new_dimension, prefix::type new_prefix, const angle& new_theta, dimension::position new_position) : vector_unit_2d(new_value,new_dimension,new_prefix,new_theta,new_position) \
148 { \
149 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
150 } \
151\
152 name##_2d::name##_2d(float new_value,const string& init_dimensions,float new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
153 { \
154 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
155 } \
156\
157 name##_2d::name##_2d(float new_value,const string& init_dimensions,const angle& new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
158 { \
159 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
160 } \
161\
162 name##_2d::name##_2d(double new_value,const string& init_dimensions,float new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
163 { \
164 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
165 } \
166\
167 name##_2d::name##_2d(double new_value,const string& init_dimensions,const angle& new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
168 { \
169 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
170 } \
171\
172 name##_2d::name##_2d(long double new_value,const string& init_dimensions,float new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
173 { \
174 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
175 } \
176\
177 name##_2d::name##_2d(long double new_value,const string& init_dimensions,const angle& new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
178 { \
179 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
180 } \
181\
182 name##_2d::name##_2d(int new_value,const string& init_dimensions,float new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
183 { \
184 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
185 } \
186\
187 name##_2d::name##_2d(int new_value,const string& init_dimensions,const angle& new_theta) : vector_unit_2d(new_value,init_dimensions,new_theta) \
188 { \
189 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
190 } \
191\
192 name##_2d::name##_2d(float new_value,const vector<dimension>& new_dimensions,float new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
193 { \
194 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
195 } \
196\
197 name##_2d::name##_2d(float new_value,const vector<dimension>& new_dimensions,const angle& new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
198 { \
199 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
200 } \
201\
202 name##_2d::name##_2d(double new_value,const vector<dimension>& new_dimensions,float new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
203 { \
204 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
205 } \
206\
207 name##_2d::name##_2d(double new_value,const vector<dimension>& new_dimensions,const angle& new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
208 { \
209 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
210 } \
211\
212 name##_2d::name##_2d(long double new_value,const vector<dimension>& new_dimensions,float new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
213 { \
214 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
215 } \
216\
217 name##_2d::name##_2d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
218 { \
219 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
220 } \
221\
222 name##_2d::name##_2d(int new_value,const vector<dimension>& new_dimensions,float new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
223 { \
224 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
225 } \
226\
227 name##_2d::name##_2d(int new_value,const vector<dimension>& new_dimensions,const angle& new_theta) : vector_unit_2d(new_value,new_dimensions,new_theta) \
228 { \
229 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
230 } \
231\
232 name##_2d::name##_2d(const scalar_unit& x,float new_theta) : vector_unit_2d(x,new_theta) \
233 { \
234 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
235 } \
236\
237 name##_2d::name##_2d(const scalar_unit& x,const angle& new_theta) : vector_unit_2d(x,new_theta) \
238 { \
239 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
240 } \
241\
242 name##_2d::name##_2d(const string& init_scalar,float new_theta) : vector_unit_2d(init_scalar,new_theta) \
243 { \
244 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
245 } \
246\
247 name##_2d::name##_2d(const string& init_scalar,const angle& new_theta) : vector_unit_2d(init_scalar,new_theta) \
248 { \
249 scalar_unit::check_dimensions(name##_2d::real_dimensions); \
250 } \
251\
252 name##_2d::name##_2d(const string& init_vector_2d) : vector_unit_2d() \
253 { \
254 vector_unit_2d::initialize_from_string(init_vector_2d); \
255 } \
256\
257 name##_2d::name##_2d(const vector_unit_2d& x) : vector_unit_2d() \
258 { \
259 if (x.has_dimensions(name##_2d::real_dimensions)) \
260 { \
261 value = x.get_value(); \
262 dimensions = x.get_dimensions(); \
263 theta = x.theta; \
264 } \
265 } \
266\
267 name##_2d::name##_2d(vector_unit_2d&& x) : vector_unit_2d() \
268 { \
269 if (x.has_dimensions(name##_2d::real_dimensions)) \
270 { \
271 value = std::move(x.get_value()); \
272 dimensions = std::move(x.get_dimensions()); \
273 theta = std::move(x.theta); \
274 } \
275 } \
276\
277 name##_2d& name##_2d::operator =(const name##_2d& x) \
278 { \
279 vector_unit_2d::operator =(x); \
280 return *this; \
281 } \
282\
283 name##_2d& name##_2d::operator =(name##_2d&& x) \
284 { \
285 vector_unit_2d::operator =(std::move(x)); \
286 return *this; \
287 } \
288const string name##_2d::dimensions_match = init_real_dimensions; \
289const vector<dimension> name##_2d::real_dimensions = create_base_dimensions(init_real_dimensions)
290
291using namespace std;
292
293namespace scifir
294{
296 {
297 public:
309 explicit vector_unit_2d(float new_value,const string& init_dimensions,float new_theta); // Example of initialization (10,"N",50)
310 explicit vector_unit_2d(float new_value,const string& init_dimensions,const angle& new_theta); // Example of initialization (10,"N",50ª)
311 explicit vector_unit_2d(double new_value,const string& init_dimensions,float new_theta); // Example of initialization (10,"N",50)
312 explicit vector_unit_2d(double new_value,const string& init_dimensions,const angle& new_theta);
313 explicit vector_unit_2d(long double new_value,const string& init_dimensions,float new_theta); // Example of initialization (10,"N",50)
314 explicit vector_unit_2d(long double new_value,const string& init_dimensions,const angle& new_theta);
315 explicit vector_unit_2d(int new_value,const string& init_dimensions,float new_theta);
316 explicit vector_unit_2d(int new_value,const string& init_dimensions,const angle& new_theta);
321 explicit vector_unit_2d(long double new_value,const vector<dimension>& new_dimensions,float new_theta);
322 explicit vector_unit_2d(long double new_value,const vector<dimension>& new_dimensions,const angle& new_theta);
325 explicit vector_unit_2d(const scalar_unit& x,float new_theta);
326 explicit vector_unit_2d(const scalar_unit& x,const angle& new_theta);
327 explicit vector_unit_2d(const string& init_scalar,float new_theta);
328 explicit vector_unit_2d(const string& init_scalar,const angle& new_theta);
329 explicit vector_unit_2d(const string& init_vector_2d); // Example of initialization string "1N 50º"
330
331 static vector_unit_2d cartesian_2d(const string& init_dimensions,float new_x,float new_y)
332 {
333 float new_value = float(std::sqrt(std::pow(new_x,2) + std::pow(new_y,2)));
336 }
337
343
344 bool operator ==(vector_unit_2d x) const;
345
347
348 void operator +=(const vector_unit_2d& x);
350
353
354 vector_unit_2d operator *(const scalar_unit& x) const;
355 vector_unit_2d operator /(const scalar_unit& x) const;
356 vector_unit_2d operator ^(const scalar_unit& x) const;
357
360 {
361 vector_unit_2d y = *this;
362 y += x;
363 return y;
364 }
365
368 {
369 vector_unit_2d y = *this;
370 y -= x;
371 return y;
372 }
373
376 {
377 vector_unit_2d y = *this;
378 y *= x;
379 return y;
380 }
381
384 {
385 vector_unit_2d y = *this;
386 y /= x;
387 return y;
388 }
389
392 {
394 }
395
398 {
400 }
401
404 {
406 }
407
410 {
411 scalar_unit::value *= std::abs(x);
412 if(x < 0)
413 {
414 theta.invert();
415 }
416 }
417
420 {
421 scalar_unit::value /= std::abs(x);
422 if(x < 0)
423 {
424 theta.invert();
425 }
426 }
427
432
437
438 inline void invert()
439 {
440 theta.invert();
441 }
442
446
448
449 protected:
451 };
452
453 string to_string(const vector_unit_2d& x);
456 vector_unit_2d sqrt_nth(const vector_unit_2d& x,int index);
459 bool same_direction(const vector_unit_2d& x,const vector_unit_2d& y);
460 bool parallel(const vector_unit_2d& x,const vector_unit_2d& y);
461 bool orthogonal(const vector_unit_2d& x,const vector_unit_2d& y);
462}
463
465
466template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
468{
470 z += y;
471 return z;
472}
473
474template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
479
480template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
482{
484 z *= y;
485 return z;
486}
487
488template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
490{
491 vector<scifir::dimension> new_dimensions = x.get_dimensions();
492 for (scifir::dimension& new_dimension : new_dimensions)
493 {
494 new_dimension.invert();
495 }
496 return scifir::vector_unit_2d(y / x.get_value(),new_dimensions,x.theta);
497}
498
500
501bool operator ==(const scifir::vector_unit_2d& x, const string& init_vector_2d);
502bool operator !=(const scifir::vector_unit_2d& x, const string& init_vector_2d);
503
504bool operator ==(const string& init_vector_2d, const scifir::vector_unit_2d& x);
505bool operator !=(const string& init_vector_2d, const scifir::vector_unit_2d& x);
506
507void operator +=(string& x, const scifir::vector_unit_2d& y);
508string operator +(const string& x, const scifir::vector_unit_2d& y);
509string operator +(const scifir::vector_unit_2d& y, const string& x);
510
511ostream& operator <<(ostream& os, const scifir::vector_unit_2d& x);
512istream& operator >>(istream& is, scifir::vector_unit_2d& x);
513
514#endif // SCIFIR_UNITS_UNITS_VECTOR_UNIT_2D_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 2D. The vector is in polar coordinates with a value and dimension...
void operator/=(T x)
It divides the numeric type x to the value. Theta is not changed.
angle theta
Angle of the vector in 2D space, in polar coordinates. As all angles of scifir-units,...
scalar_unit y_projection() const
It creates the y projection of the vector, returning it as a scalar_unit of the same dimensions,...
vector_unit_2d operator+(const vector_unit_2d &x) const
Addition of vectors in 2D. It creates a new vector as the addition of the other two.
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....
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.
void operator*=(T x)
It multiplies the numeric type x to the value. Theta is not changed.
void initialize_from_string(string init_vector_2d)
Initializes the member-variables with the initialization string of vector_unit_2d init_vector_2d.
void operator-=(vector_unit_2d x)
The vector_unit_2d is substracted as vector, in polar coordinates. The substraction of vectors is use...
void point_to(direction::name x)
Theta is set to the direction specified in 2D. Possible values are LEFT, RIGHT, TOP,...
void operator+=(const vector_unit_2d &x)
The vector_unit_2d is summed as vector, in polar coordinates. The addition of vectors is used for the...
vector_unit_2d operator*(const scalar_unit &x) const
It creates a new vector_unit_2d scaling a vector_unit_2d by the scalar_unit x.
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....
void invert()
Changes the direction of the vector to the opposite direction. It does that by adding 180 degrees to ...
vector_unit_2d & operator=(const vector_unit_2d &x)
Copy assignment. The member-variables are copied from the vector_unit_2d x.
vector_unit_2d operator-(vector_unit_2d x) const
Substraction of vectors in 2D. It creates a new vector as the difference of the other two.
bool operator==(vector_unit_2d x) const
Comparison operator. Two vector_unit_2d are equal if their value, dimensions and theta are the same.
scalar_unit x_projection() const
It creates the x projection of the vector, returning it as a scalar_unit of the same dimensions,...
vector_unit_2d()
Default constructor. The value is set to 0, the dimensions are empty and theta is 0.
static vector_unit_2d cartesian_2d(const string &init_dimensions, float new_x, float new_y)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
vector_unit_2d operator^(const scalar_unit &x) const
It powers a vector by a scalar_unit x if that scalar_unit has empty dimensions.
vector_unit_2d operator/(const scalar_unit &x) const
It creates a new vector_unit_2d scaling a vector_unit_2d by the inverse of the scalar_unit x.
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
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.
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_2d operator*(const scifir::scalar_unit &x, const scifir::vector_unit_2d &y)
It creates a new vector_unit_3d scaling a vector_unit_3d by the scalar_unit x.
scifir::vector_unit_2d operator/(const T y, const scifir::vector_unit_2d &x)
It creates a new vector as the division of the value x to the numeric type. Theta is not changed.
bool operator==(const scifir::vector_unit_2d &x, const string &init_vector_2d)
Returns true if x is equal to the vector_unit_2d initialized with the string being compared....
istream & operator>>(istream &is, scifir::vector_unit_2d &x)
Allows that an istream initializes by string a vector_unit_2d x.
void operator+=(string &x, const scifir::vector_unit_2d &y)
Concatenates the string representation of the vector_unit_2d y to the string x.
bool operator!=(const scifir::vector_unit_2d &x, const scifir::vector_unit_2d &y)
Comparison operator. Two vector_unit_2d are not equal if their value, dimensions or theta are differe...
scifir::vector_unit_2d operator+(const T y, const scifir::vector_unit_2d &x)
It creates a new vector as the addition of the numeric type x to the value. Theta is not changed.
ostream & operator<<(ostream &os, const scifir::vector_unit_2d &x)
Adds the string representation of the vector_unit_2d x to an output stream os.
scifir::vector_unit_2d operator-(const T y, const scifir::vector_unit_2d &x)
Substraction of vectors in 2D. It creates a new vector as the difference of the other two.