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
coordinates_3d.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_COORDINATES_COORDINATES_3D_HPP_INCLUDED
2#define SCIFIR_UNITS_COORDINATES_COORDINATES_3D_HPP_INCLUDED
3
4#include "../meca_number/angle.hpp"
5#include "../units/base_units.hpp"
6#include "../derived_units/physics_units.hpp"
7#include "../util/types.hpp"
8#include "../units/constants.hpp"
9#include "./latitude.hpp"
10#include "./longitude.hpp"
11
12#include <iostream>
13#include <string>
14#include <cmath>
15
16using namespace std;
17
18namespace scifir
19{
20 enum class cardinale_point { NORTH, SOUTH, EAST, WEST };
21
23 {
28 long double G = std::pow(p.get_value(),2) + (1.0f - e_square.get_value()) * std::pow(z.get_value(),2) - e_square.get_value() * (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2));
29 long double c = (scifir::pow(e_square,2) * F * scifir::pow(p,2)).get_value() / std::pow(G,3);
30 long double s = std::cbrt(1.0f + c + std::sqrt(std::pow(c,2) + 2.0f * c));
31 long double k = s + 1.0f + (1.0f/s);
33 scalar_unit Q = scifir::sqrt(1.0f + 2.0f * scifir::pow(e_square,2) * P);
34 scalar_unit r0 = -1.0f * ((P * e_square * p)/(1.0f + Q)) + scifir::sqrt((1.0f/2.0f) * scifir::pow(WGS84_EARTH_SEMIAXIS_A,2) * (1.0f + (1.0f / Q)) - (P * (1.0f - e_square) * scifir::pow(z,2))/(Q * (1.0f + Q)) - (1.0f/2.0f) * P * scifir::pow(p,2));
37 return latitude(scifir::atan(float((z + e_prim_square * z0)/p)));
38 }
39
41 {
42 return longitude(scifir::atan2(float(y),float(x)));
43 }
44
46 {
51 long double G = std::pow(p.get_value(),2) + (1.0f - e_square.get_value()) * std::pow(z.get_value(),2) - e_square.get_value() * (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2));
52 long double c = (scifir::pow(e_square,2) * F * scifir::pow(p,2)).get_value() / std::pow(G,3);
53 long double s = std::cbrt(1.0f + c + std::sqrt(std::pow(c,2) + 2.0f * c));
54 long double k = s + 1.0f + (1.0f/s);
56 scalar_unit Q = scifir::sqrt(1.0f + 2.0f * scifir::pow(e_square,2) * P);
57 scalar_unit r0 = -1.0f * ((P * e_square * p)/(1.0f + Q)) + scifir::sqrt((1.0f/2.0f) * scifir::pow(WGS84_EARTH_SEMIAXIS_A,2) * (1.0f + (1.0f / Q)) - (P * (1.0f - e_square) * scifir::pow(z,2))/(Q * (1.0f + Q)) - (1.0f/2.0f) * P * scifir::pow(p,2));
60 return scalar_unit(U.get_value() * (1.0f - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2) / (WGS84_EARTH_SEMIAXIS_A.get_value() * V.get_value())),{ dimension(dimension::METRE,prefix::NONE,dimension::NUMERATOR) });
61 }
62
64 {
65 long double e_square = 0.00669437999014l;
66 long double n = WGS84_EARTH_SEMIAXIS_A.get_value() / std::sqrt(1 - e_square * scifir::sin(latitude) * scifir::sin(latitude));
67 altitude.change_dimensions("m");
69 }
70
72 {
73 long double e_square = 0.00669437999014l;
74 long double n = WGS84_EARTH_SEMIAXIS_A.get_value() / std::sqrt(1 - e_square * scifir::sin(latitude) * scifir::sin(latitude));
75 altitude.change_dimensions("m");
77 }
78
80 {
81 long double e_square = 0.00669437999014l;
82 long double n = WGS84_EARTH_SEMIAXIS_A.get_value() / std::sqrt(1 - e_square * scifir::sin(latitude) * scifir::sin(latitude));
83 altitude.change_dimensions("m");
84 return ((1 - e_square) * n + altitude) * scifir::sin(latitude);
85 }
86
87 inline latitude ECEF_to_LLA_latitude(float x, float y, float z)
88 {
89 long double e_square = (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2))/std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2);
90 long double e_prim_square = (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2))/std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2);
91 long double p = std::sqrt(std::pow(x,2) + std::pow(y,2));
92 long double F = 54.0f * std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2) * std::pow(z,2);
93 long double G = std::pow(p,2) + (1.0f - e_square) * std::pow(z,2) - e_square * (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2));
94 long double c = std::pow(e_square,2) * F * std::pow(p,2) / std::pow(G,3);
95 long double s = std::cbrt(1.0f + c + std::sqrt(std::pow(c,2) + 2.0f * c));
96 long double k = s + 1.0f + (1.0f/s);
97 long double P = F/(3.0f * std::pow(k,2) * std::pow(G,2));
98 long double Q = std::sqrt(1.0f + 2.0f * std::pow(e_square,2) * P);
99 long double r0 = -1.0f * ((P * e_square * p)/(1.0f + Q)) + std::sqrt((1.0f/2.0f) * std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) * (1.0f + (1.0f / Q)) - (P * (1.0f - e_square) * std::pow(z,2))/(Q * (1.0f + Q)) - (1.0f/2.0f) * P * std::pow(p,2));
100 long double V = std::sqrt(std::pow(p - e_square * r0,2) + (1.0f - e_square) * std::pow(z,2));
101 long double z0 = std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2)*z/(WGS84_EARTH_SEMIAXIS_A.get_value() * V);
102 return latitude(scifir::atan(float((z + e_prim_square * z0)/p)));
103 }
104
105 inline longitude ECEF_to_LLA_longitude(float x, float y, float z)
106 {
107 return longitude(scifir::atan2(y,x));
108 }
109
110 inline float ECEF_to_LLA_altitude(float x, float y, float z)
111 {
112 long double e_square = (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2))/std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2);
113 long double e_prim_square = (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2))/std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2);
114 long double p = std::sqrt(std::pow(x,2) + std::pow(y,2));
115 long double F = 54.0f * std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2) * std::pow(z,2);
116 long double G = std::pow(p,2) + (1.0f - e_square) * std::pow(z,2) - e_square * (std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2));
117 long double c = std::pow(e_square,2) * F * std::pow(p,2) / std::pow(G,3);
118 long double s = std::cbrt(1.0f + c + std::sqrt(std::pow(c,2) + 2.0f * c));
119 long double k = s + 1.0f + (1.0f/s);
120 long double P = F/(3.0f * std::pow(k,2) * std::pow(G,2));
121 long double Q = std::sqrt(1.0f + 2.0f * std::pow(e_square,2) * P);
122 long double r0 = -1.0f * ((P * e_square * p)/(1.0f + Q)) + std::sqrt((1.0f/2.0f) * std::pow(WGS84_EARTH_SEMIAXIS_A.get_value(),2) * (1.0f + (1.0f / Q)) - (P * (1.0f - e_square) * std::pow(z,2))/(Q * (1.0f + Q)) - (1.0f/2.0f) * P * std::pow(p,2));
123 long double U = std::sqrt(std::pow(p - e_square * r0,2) + std::pow(z,2));
124 long double V = std::sqrt(std::pow(p - e_square * r0,2) + (1.0f - e_square) * std::pow(z,2));
125 return U * (1.0f - std::pow(WGS84_EARTH_SEMIAXIS_B.get_value(),2) / (WGS84_EARTH_SEMIAXIS_A.get_value() * V));
126 }
127
128 template<typename T = length>
130 {
131 public:
133
134 coordinates_3d() : x(),y(),z()
135 {}
136
139
142
144 {}
145
150
155
160
180
185
187 {
188 x = x_coordinates.x;
189 y = x_coordinates.y;
190 z = x_coordinates.z;
191 return *this;
192 }
193
195 {
196 x = std::move(x_coordinates.x);
197 y = std::move(x_coordinates.y);
198 z = std::move(x_coordinates.z);
199 return *this;
200 }
201
207
214
215 T get_p() const
216 {
217 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2)));
218 }
219
221 {
222 return scifir::atan(float(y/x));
223 }
224
225 T get_r() const
226 {
227 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2) + scifir::pow(z,2)));
228 }
229
231 {
233 }
234
236 {
237 return ECEF_to_LLA_latitude(x,y,z);
238 }
239
241 {
242 return ECEF_to_LLA_longitude(x,y,z);
243 }
244
246 {
247 return ECEF_to_LLA_altitude(x,y,z);
248 }
249
251 {
252 x = new_x;
253 y = new_y;
254 z = new_z;
255 }
256
258 {
259 new_z.change_dimensions(new_p);
262 z = new_z;
263 }
264
271
278
286
294
302
304 {
305 x += x_displacement.x_projection();
306 y += x_displacement.y_projection();
307 z += x_displacement.z_projection();
308 }
309
311 {
312 x += new_x;
313 y += new_y;
314 z += new_z;
315 }
316
318 {
319 new_z.change_dimensions(new_p);
322 z += new_z;
323 }
324
331
333 {
334 return T(scifir::sqrt(scifir::pow(x,2) + scifir::pow(y,2) + scifir::pow(z,2)));
335 }
336
337 string display_cartesian() const
338 {
340 out << "(" << x << "," << y << "," << z << ")";
341 return out.str();
342 }
343
344 string display_cylindrical() const
345 {
347 out << "(" << get_p() << "," << get_theta() << "," << z << ")";
348 return out.str();
349 }
350
351 string display_spherical() const
352 {
354 out << "(" << get_r() << "," << get_theta() << "," << get_phi() << ")";
355 return out.str();
356 }
357
358 string display_geographical() const
359 {
361 out << "(" << get_latitude() << "," << get_longitude() << "," << get_altitude() << ")";
362 return out.str();
363 }
364
368
369 protected:
371 {
372 vector<string> values;
373 if (init_coordinates_3d.front() == '(')
374 {
375 init_coordinates_3d.erase(0,1);
376 }
377 if (init_coordinates_3d.back() == ')')
378 {
380 }
381 boost::split(values,init_coordinates_3d,boost::is_any_of(","));
382 if (values.size() == 3)
383 {
384 if (is_latitude(values[0]))
385 {
386 if (is_longitude(values[1]))
387 {
388 if (!is_angle(values[2]))
389 {
390 cout << "values[0]: " << values[0] << endl;
391 cout << "values[1]: " << values[1] << endl;
392 cout << "values[2]: " << values[2] << endl;
393 set_position(latitude(values[0]),longitude(values[1]),T(values[2]));
394 }
395 }
396 }
397 else
398 {
399 if (is_angle(values[1]))
400 {
401 if (is_angle(values[2]))
402 {
403 set_position(T(values[0]),angle(values[1]),angle(values[2]));
404 }
405 else
406 {
407 set_position(T(values[0]),angle(values[1]),T(values[2]));
408 }
409 }
410 else
411 {
412 if (!is_angle(values[2]))
413 {
414 set_position(T(values[0]),T(values[1]),T(values[2]));
415 }
416 }
417 }
418 }
419 }
420 };
421
422 template<>
424 {
425 public:
426 coordinates_3d() : x(),y(),z()
427 {}
428
431
434
435 explicit coordinates_3d(float new_x,float new_y,float new_z) : x(new_x),y(new_y),z(new_z)
436 {}
437
438 explicit coordinates_3d(float new_p,const angle& new_theta,float new_z)
439 {
441 }
442
443 explicit coordinates_3d(float new_r,const angle& new_theta,const angle& new_phi)
444 {
446 }
447
452
472
477
479 {
480 x = x_coordinates.x;
481 y = x_coordinates.y;
482 z = x_coordinates.z;
483 return *this;
484 }
485
487 {
488 x = std::move(x_coordinates.x);
489 y = std::move(x_coordinates.y);
490 z = std::move(x_coordinates.z);
491 return *this;
492 }
493
499
500 float get_p() const
501 {
502 return float(std::sqrt(std::pow(x,2) + std::pow(y,2)));
503 }
504
506 {
507 return scifir::atan(float(y/x));
508 }
509
510 float get_r() const
511 {
512 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
513 }
514
516 {
517 return angle(scifir::acos_degree(float(z/std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)))));
518 }
519
521 {
522 return ECEF_to_LLA_latitude(x,y,z);
523 }
524
526 {
527 return ECEF_to_LLA_longitude(x,y,z);
528 }
529
530 float get_altitude() const
531 {
532 return ECEF_to_LLA_altitude(x,y,z);
533 }
534
535 void set_position(float new_x,float new_y,float new_z)
536 {
537 x = new_x;
538 y = new_y;
539 z = new_z;
540 }
541
542 void set_position(float new_p,const angle& new_theta,float new_z)
543 {
546 z = new_z;
547 }
548
555
562
564 {
565 float y_coord = y;
566 float z_coord = z;
569 }
570
572 {
573 float x_coord = x;
574 float z_coord = z;
577 }
578
580 {
581 float x_coord = x;
582 float y_coord = y;
585 }
586
588 {
589 x += float(x_displacement.x_projection());
590 y += float(x_displacement.y_projection());
591 z += float(x_displacement.z_projection());
592 }
593
594 void move(float new_x,float new_y,float new_z)
595 {
596 x += new_x;
597 y += new_y;
598 z += new_z;
599 }
600
601 void move(float new_p,const angle& new_theta,float new_z)
602 {
605 z += new_z;
606 }
607
614
615 float distance_to_origin() const
616 {
617 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
618 }
619
620 string display_cartesian() const
621 {
623 out << "(" << display_float(x) << "," << display_float(y) << "," << display_float(z) << ")";
624 return out.str();
625 }
626
627 string display_cylindrical() const
628 {
630 out << "(" << display_float(get_p()) << "," << get_theta() << "," << display_float(z) << ")";
631 return out.str();
632 }
633
634 string display_spherical() const
635 {
637 out << "(" << display_float(get_r()) << "," << get_theta() << "," << get_phi() << ")";
638 return out.str();
639 }
640
641 string display_geographical() const
642 {
644 out << "(" << get_latitude() << "," << get_longitude() << "," << display_float(get_altitude()) << ")";
645 return out.str();
646 }
647
648 float x;
649 float y;
650 float z;
651
652 private:
654 {
655 vector<string> values;
656 if (init_coordinates_3d.front() == '(')
657 {
658 init_coordinates_3d.erase(0,1);
659 }
660 if (init_coordinates_3d.back() == ')')
661 {
663 }
664 boost::split(values,init_coordinates_3d,boost::is_any_of(","));
665 if (values.size() == 3)
666 {
667 if (values[0] == "" or values[1] == "" or values[2] == "")
668 {
669 return;
670 }
671 if (is_latitude(values[0]))
672 {
673 if (is_longitude(values[1]))
674 {
675 if (!is_angle(values[2]))
676 {
677 set_position(angle(values[0]),angle(values[1]),stof(values[2]));
678 }
679 }
680 }
681 else
682 {
683 if (is_angle(values[1]))
684 {
685 if (is_angle(values[2]))
686 {
687 set_position(stof(values[0]),angle(values[1]),angle(values[2]));
688 }
689 else
690 {
691 set_position(stof(values[0]),angle(values[1]),stof(values[2]));
692 }
693 }
694 else
695 {
696 if (!is_angle(values[2]))
697 {
698 set_position(stof(values[0]),stof(values[1]),stof(values[2]));
699 }
700 }
701 }
702 }
703 }
704 };
705
706 string to_string(cardinale_point x);
707
708 template<typename T>
710 {
711 return x.display_cartesian();
712 }
713
714 string to_string(const coordinates_3d<float>& x);
715
717
718 template<typename T,typename U>
720 {
721 return T(scifir::sqrt(scifir::pow(x.x - y.x,2) + scifir::pow(x.y - y.y,2) + scifir::pow(x.z - y.z,2)));
722 }
723
724 float distance(const coordinates_3d<float>& x,const coordinates_3d<float>& y);
725
727 {
729 return scalar_unit(std::sqrt(std::pow(float(x),2) + std::pow(float(y),2)),x.get_dimensions());
730 }
731
733 {
735 return angle(scifir::atan_degree(float(y) / float(x)));
736 }
737
739 {
740 return z;
741 }
742
744 {
747 return scalar_unit(std::sqrt(std::pow(float(x),2) + std::pow(float(y),2) + std::pow(float(z),2)),x.get_dimensions());
748 }
749
751 {
753 return angle(scifir::atan_degree(float(y) / float(x)));
754 }
755
757 {
760 return angle(scifir::acos_degree(float(z) / float(std::sqrt(std::pow(float(x),2) + std::pow(float(y),2) + std::pow(float(z),2)))));
761 }
762
763 inline scalar_unit spherical_to_cartesian_3d_x(const scalar_unit& r,const angle& theta, const angle& phi)
764 {
765 return r * scifir::cos(theta) * scifir::sin(phi);
766 }
767
768 inline scalar_unit spherical_to_cartesian_3d_y(const scalar_unit& r,const angle& theta, const angle& phi)
769 {
770 return r * scifir::sin(theta) * scifir::sin(phi);
771 }
772
773 inline scalar_unit spherical_to_cartesian_3d_z(const scalar_unit& r,const angle& theta, const angle& phi)
774 {
775 return r * scifir::cos(phi);
776 }
777
778 inline scalar_unit spherical_to_cylindrical_p(const scalar_unit& r,const angle& theta, const angle& phi)
779 {
780 return r * scifir::sin(phi);
781 }
782
783 inline angle spherical_to_cylindrical_theta(const scalar_unit& r,const angle& theta, const angle& phi)
784 {
785 return theta;
786 }
787
788 inline scalar_unit spherical_to_cylindrical_z(const scalar_unit& r,const angle& theta, const angle& phi)
789 {
790 return r * scifir::cos(phi);
791 }
792
794 {
795 return p * scifir::cos(theta);
796 }
797
799 {
800 return p * scifir::sin(theta);
801 }
802
804 {
805 return z;
806 }
807
809 {
811 return scalar_unit(std::sqrt(std::pow(float(p),2) + std::pow(float(z),2)),p.get_dimensions());
812 }
813
815 {
816 return theta;
817 }
818
820 {
822 return angle(scifir::atan_degree(float(p) / float(z)));
823 }
824
825 inline float cartesian_3d_to_cylindrical_p(float x,float y,float z)
826 {
827 return float(std::sqrt(std::pow(x,2) + std::pow(y,2)));
828 }
829
830 inline angle cartesian_3d_to_cylindrical_theta(float x,float y,float z)
831 {
832 return angle(scifir::atan_degree(y / x));
833 }
834
835 inline float cartesian_3d_to_cylindrical_z(float x,float y,float z)
836 {
837 return z;
838 }
839
840 inline float cartesian_3d_to_spherical_r(float x,float y,float z)
841 {
842 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
843 }
844
845 inline angle cartesian_3d_to_spherical_theta(float x,float y,float z)
846 {
847 return angle(scifir::atan_degree(y / x));
848 }
849
850 inline angle cartesian_3d_to_spherical_phi(float x,float y,float z)
851 {
852 return angle(scifir::acos_degree(z / float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)))));
853 }
854
855 inline float spherical_to_cartesian_3d_x(float r,const angle& theta, const angle& phi)
856 {
857 return r * scifir::cos(theta) * scifir::sin(phi);
858 }
859
860 inline float spherical_to_cartesian_3d_y(float r,const angle& theta, const angle& phi)
861 {
862 return r * scifir::sin(theta) * scifir::sin(phi);
863 }
864
865 inline float spherical_to_cartesian_3d_z(float r,const angle& theta, const angle& phi)
866 {
867 return r * scifir::cos(phi);
868 }
869
870 inline float spherical_to_cylindrical_p(float r,const angle& theta, const angle& phi)
871 {
872 return r * scifir::sin(phi);
873 }
874
875 inline angle spherical_to_cylindrical_theta(float r,const angle& theta, const angle& phi)
876 {
877 return theta;
878 }
879
880 inline float spherical_to_cylindrical_z(float r,const angle& theta, const angle& phi)
881 {
882 return r * scifir::cos(phi);
883 }
884
885 inline float cylindrical_to_cartesian_3d_x(float p,const angle& theta, float z)
886 {
887 return p * scifir::cos(theta);
888 }
889
890 inline float cylindrical_to_cartesian_3d_y(float p,const angle& theta, float z)
891 {
892 return p * scifir::sin(theta);
893 }
894
895 inline float cylindrical_to_cartesian_3d_z(float p,const angle& theta, float z)
896 {
897 return z;
898 }
899
900 inline float cylindrical_to_spherical_r(float p,const angle& theta, float z)
901 {
902 return float(std::sqrt(std::pow(p,2) + std::pow(z,2)));
903 }
904
905 inline angle cylindrical_to_spherical_theta(float p,const angle& theta, float z)
906 {
907 return theta;
908 }
909
910 inline angle cylindrical_to_spherical_phi(float p,const angle& theta, float z)
911 {
912 return angle(scifir::atan_degree(p / z));
913 }
914}
915
916template<typename T,typename U>
918{
919 if (x.x == y.x and x.y == y.y and x.z == y.z)
920 {
921 return true;
922 }
923 else
924 {
925 return false;
926 }
927}
928
929template<typename T,typename U>
931{
932 return !(x == y);
933}
934
935template<typename T>
936bool operator ==(const scifir::coordinates_3d<T>& x, const string& init_coordinates_3d)
937{
938 scifir::coordinates_3d<T> y(init_coordinates_3d);
939 return (x == y);
940}
941
942template<typename T>
943bool operator !=(const scifir::coordinates_3d<T>& x, const string& init_coordinates_3d)
944{
945 return !(x == init_coordinates_3d);
946}
947
948template<typename T>
949bool operator ==(const string& init_coordinates_3d, const scifir::coordinates_3d<T>& x)
950{
951 scifir::coordinates_3d<T> y(init_coordinates_3d);
952 return (x == y);
953}
954
955template<typename T>
956bool operator !=(const string& init_coordinates_3d, const scifir::coordinates_3d<T>& x)
957{
958 return !(init_coordinates_3d == x);
959}
960
961template<typename T>
962void operator +=(string& x, const scifir::coordinates_3d<T>& y)
963{
964 x += to_string(y);
965}
966
967template<typename T>
968string operator +(const string& x,const scifir::coordinates_3d<T>& y)
969{
970 return x + to_string(y);
971}
972
973template<typename T>
974string operator +(const scifir::coordinates_3d<T>& x,const string& y)
975{
976 return to_string(x) + y;
977}
978
979template<typename T>
980ostream& operator <<(ostream& os, const scifir::coordinates_3d<T>& x)
981{
982 return os << to_string(x);
983}
984
985ostream& operator <<(ostream& os,const scifir::coordinates_3d<float>& x);
986
987template<typename T>
988istream& operator >>(istream& is, scifir::coordinates_3d<T>& x)
989{
990 char a[256];
991 is.getline(a, 256);
992 string b(a);
993 boost::trim(b);
995 return is;
996}
997
998#endif // SCIFIR_UNITS_COORDINATES_COORDINATES_3D_HPP_INCLUDED
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77
string display_cartesian() const
void move(const scalar_unit &x_value)
coordinates_3d(const string &init_coordinates_3d)
Constructor. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates...
longitude get_longitude() const
Returns the longitude in geographical coordinates. In this case, coordinates_3d represents all the as...
coordinates_3d(coordinates_3d< length >::type coordinates_type, const string &coord1, const string &coord2, const string &coord3)
float get_altitude() const
Returns the altitude in geographical coordinates. In this case, coordinates_3d represents all the ast...
coordinates_3d(float new_r, const angle &new_theta, const angle &new_phi)
Constructor. Initializes x, y and z with spherical coordinates.
string display_cylindrical() const
Displays the coordinates in cylindrical coordinates.
void move(const displacement_3d &x_displacement)
Moves x, y and z in the vector x_displacement given.
string display_spherical() const
Displays the coordinates in spherical coordinates.
coordinates_3d()
Default constructor. Initializes x, y and z to 0, with the default dimensions.
latitude get_latitude() const
Returns the latitude in geographical coordinates. In this case, coordinates_3d represents all the ast...
coordinates_3d(float new_x, float new_y, float new_z)
Constructor. Initializes x, y and z to be new_x, new_y and new_z.
float y
The position in the edge y, with type float.
angle get_theta() const
Returns the value of theta in cylindrical and spherical coordinates (it's the same theta).
float distance_to_origin() const
Calculates the distance to the origin.
coordinates_3d(const angle &new_latitude, const angle &new_longitude, float new_altitude)
Constructor. Initializes x, y and z with geographical coordinates. Currently geographical coordinates...
coordinates_3d(coordinates_3d< float > &&x_coordinates)
Move constructor. Initializes x, y and z to the x, y and z of x_coordinates.
void rotate_in_x(const angle &x_angle)
Rotates around the edge x the amount of the param x_angle.
float x
The position in the edge x, with type float.
void set_position(const angle &new_latitude, const angle &new_longitude, float new_altitude)
Sets x, y and z calculated from the geographical coordinates given.
void initialize_from_string(string init_coordinates_3d)
Internal function. Initializes x, y and z with the initialization string of coordinates_3d init_coord...
void set_position(float new_r, const angle &new_theta, const angle &new_phi)
Sets x, y and z calculated from the spherical coordinates given.
void move(float new_p, const angle &new_theta, float new_z)
Moves x, y and z in the cylindrical coordinates given.
void rotate_in_z(const angle &x_angle)
Rotates around the edge z the amount of the param x_angle.
coordinates_3d(float new_p, const angle &new_theta, float new_z)
Constructor. Initializes x, y and z with cylindrical coordinates.
float get_r() const
Returns the value of r in spherical coordinates.
void move(float new_x, float new_y, float new_z)
Moves x in new_x, y in new_y and z in new_z.
angle get_phi() const
Returns the value of phi in spherical coordinates.
void rotate_in_y(const angle &x_angle)
Rotates around the edge y the amount of the param x_angle.
string display_cartesian() const
Displays the coordinates in cartesian coordinates.
void move(float new_r, const angle &new_theta, const angle &new_phi)
Moves x, y and z in the spherical coordinates given.
void set_position(float new_x, float new_y, float new_z)
Sets x, y and z to the new_x, new_y and new_z.
float z
The position in the edge z, with type float.
coordinates_3d(const coordinates_3d< float > &x_coordinates)
Copy constructor. Initializes x, y and z to the x, y and z of x_coordinates.
string display_geographical() const
Displays the coordinates in geographical coordinates.
float get_p() const
Returns the value of p in cylindrical coordinates.
void set_position(float new_p, const angle &new_theta, float new_z)
Sets x, y and z calculated from the cylindrical coordinates given.
Class that represents the position in 3D spaces. The space can be a length or, for the case of imagin...
string display_geographical() const
Displays the coordinates in geographical coordinates.
coordinates_3d(const string &init_coordinates_3d)
Constructor. Initializes x, y and z with the initialization string of coordinates_3d init_coordinates...
coordinates_3d(const angle &new_latitude, const angle &new_longitude, const scalar_unit &new_altitude)
string display_cylindrical() const
Displays the coordinates in cylindrical coordinates.
void set_position(const scalar_unit &new_x, const scalar_unit &new_y, const scalar_unit &new_z)
void rotate_in_x(const angle &x_angle)
Rotates around the edge x the amount of the param x_angle.
angle get_theta() const
Returns the value of theta in cylindrical and spherical coordinates (it's the same theta).
void move(const displacement_3d &x_displacement)
Moves x, y and z in the vector x_displacement given.
angle get_phi() const
Returns the value of phi in spherical coordinates.
T y
The position in the edge y. The space can have dimensions of length or of any custom dimension.
void set_position(const scalar_unit &new_p, const angle &new_theta, scalar_unit new_z)
void set_position(const scalar_unit &new_r, const angle &new_theta, const angle &new_phi)
T get_p() const
Returns the value of p in cylindrical coordinates.
void rotate_in_y(const angle &x_angle)
Rotates around the edge y the amount of the param x_angle.
void set_position(const latitude &new_latitude, const longitude &new_longitude, const scalar_unit &new_altitude)
T get_r() const
Returns the value of r in spherical coordinates.
coordinates_3d(coordinates_3d::type coordinates_type, const string &coord1, const string &coord2, const string &coord3)
coordinates_3d()
Default constructor. Initializes x, y and z to 0, with the default dimensions.
latitude get_latitude() const
Returns the latitude in LLA geographical coordinates. In this case, coordinates_3d represents all the...
scalar_unit get_altitude() const
Returns the altitude in LLA geographical coordinates. In this case, coordinates_3d represents all the...
coordinates_3d(const scalar_unit &new_x, const scalar_unit &new_y, const scalar_unit &new_z)
longitude get_longitude() const
Returns the longitude in LLA geographical coordinates. In this case, coordinates_3d represents all th...
coordinates_3d(const scalar_unit &new_r, const angle &new_theta, const angle &new_phi)
void move(const scalar_unit &new_p, const angle &new_theta, scalar_unit new_z)
static coordinates_3d< T > origin(const coordinates_3d< T > &origin, const coordinates_3d< T > &coordinates)
string display_spherical() const
Displays the coordinates in spherical coordinates.
coordinates_3d< T > & operator=(const coordinates_3d< T > &x_coordinates)
Copy assignment. Assigns x, y and z to the same values as the x, y and z of x_coordinates.
T x
The position in the edge x. The space can have dimensions of length or of any custom dimension.
coordinates_3d(const scalar_unit &new_p, const angle &new_theta, scalar_unit new_z)
void rotate_in_z(const angle &x_angle)
Rotates around the edge z the amount of the param x_angle.
void move(const scalar_unit &new_r, const angle &new_theta, const angle &new_phi)
string display_cartesian() const
Displays the coordinates in cartesian coordinates.
coordinates_3d(coordinates_3d< T > &&x_coordinates)
Move constructor. Initializes x, y and z to the x, y and z of x_coordinates.
void initialize_from_string(string init_coordinates_3d)
Internal function. Initializes x, y and z with the initialization string of coordinates_3d init_coord...
T z
The position in the edge z. The space can have dimensions of length or of any custom dimension.
coordinates_3d(const coordinates_3d< T > &x_coordinates)
Copy constructor. Initializes x, y and z to the x, y and z of x_coordinates.
T distance_to_origin() const
Calculates the distance to the origin.
void move(const scalar_unit &new_x, const scalar_unit &new_y, const scalar_unit &new_z)
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
@ METRE
Meter, plural meters. SI dimension of length. Symbol m.
Definition dimension.hpp:35
@ NONE
There is no prefix. Then, the dimension is not increased or decreased by some factor.
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.
void change_dimensions(const string &init_dimensions)
Changes the dimensions to the dimensions specified by the initialization string of dimensions.
const float & get_value() const
Read-only getter of the value.
ostream & operator<<(ostream &os, const scifir::coordinates_3d< T > &x)
Adds the string representation of the coordinates_3d x to an output stream os.
void operator+=(string &x, const scifir::coordinates_3d< T > &y)
Concatenates to the string x the string representation of the coordinates_3d y.
bool operator==(const scifir::coordinates_3d< T > &x, const scifir::coordinates_3d< U > &y)
Returns true if both coordinates are equal in the three components.
bool operator!=(const scifir::coordinates_3d< T > &x, const scifir::coordinates_3d< U > &y)
Returns true if both coordinates are different.
string operator+(const string &x, const scifir::coordinates_3d< T > &y)
Concatenates the string x and the string representation of the coordinates_3d y.
istream & operator>>(istream &is, scifir::coordinates_3d< T > &x)
Allows that an istream initializes by string a coordinates_3d x.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
cardinale_point create_cardinale_point(const string &x)
bool is_latitude(const string &init_latitude)
Definition latitude.cpp:199
scalar_unit ECEF_to_LLA_altitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
scalar_unit spherical_to_cartesian_3d_z(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the z coordinate of the cartesian coordinates in 3D given the r, theta and phi of spherical c...
scalar_unit cylindrical_to_spherical_r(const scalar_unit &p, const angle &theta, scalar_unit z)
Returns the r coordinate of the spherical coordinates given the p, theta and z of cylindrical coordin...
angle cartesian_3d_to_cylindrical_theta(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
Returns the theta coordinate of the cylindrical coordinates given the x, y and z of cartesian coordin...
scalar_unit spherical_to_cartesian_3d_y(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the y coordinate of the cartesian coordinates in 3D given the r, theta and phi of spherical c...
angle cartesian_3d_to_spherical_theta(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
Returns the theta coordinate of the spherical coordinates given the x, y and z of cartesian coordinat...
angle spherical_to_cylindrical_theta(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the theta coordinate of the cylindrical coordinates given the r, theta and phi of spherical c...
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
scalar_unit LLA_to_ECEF_x(const latitude &latitude, const longitude &longitude, scalar_unit altitude)
scalar_unit spherical_to_cylindrical_p(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the p coordinate of the cylindrical coordinates given the r, theta and phi of spherical coord...
scalar_unit pow(const scalar_unit &x, int exponent)
Exponentiates a scalar_unit to some numeric type, the dimensions are also exponentiated.
scalar_unit LLA_to_ECEF_z(const latitude &latitude, const longitude &longitude, scalar_unit altitude)
bool is_longitude(const string &init_longitude)
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
longitude ECEF_to_LLA_longitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
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
angle atan2(float y, float x)
Definition angle.cpp:456
float distance(const coordinates_1d< float > &x, const coordinates_1d< float > &y)
scalar_unit cylindrical_to_cartesian_3d_y(const scalar_unit &p, const angle &theta, const scalar_unit &z)
Returns the y coordinate of the cartesian coordinates in 3D given the p, theta and z of cylindrical c...
scalar_unit spherical_to_cylindrical_z(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the z coordinate of the cylindrical coordinates given the r, theta and phi of spherical coord...
angle atan(float x)
Calculates the atan of some value x and returns the result as angle in degrees.
Definition angle.cpp:451
string display_float(const float &value, int number_of_decimals)
Definition types.cpp:36
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 cartesian_3d_to_cylindrical_p(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
Returns the p coordinate of the cylindrical coordinates given the x, y and z of cartesian coordinates...
latitude ECEF_to_LLA_latitude(const scalar_unit &x, scalar_unit y, const scalar_unit &z)
scalar_unit cartesian_3d_to_spherical_r(const scalar_unit &x, scalar_unit y, scalar_unit z)
Returns the r coordinate of the spherical coordinates given the x, y and z of cartesian coordinates i...
scalar_unit LLA_to_ECEF_y(const latitude &latitude, const longitude &longitude, scalar_unit altitude)
scalar_unit cartesian_3d_to_cylindrical_z(const scalar_unit &x, const scalar_unit &y, const scalar_unit &z)
Returns the z coordinate of the cylindrical coordinates given the x, y and z of cartesian coordinates...
scalar_unit cylindrical_to_cartesian_3d_x(const scalar_unit &p, const angle &theta, const scalar_unit &z)
Returns the x coordinate of the cartesian coordinates in 3D given the p, theta and z of cylindrical c...
angle cylindrical_to_spherical_phi(const scalar_unit &p, const angle &theta, scalar_unit z)
Returns the phi coordinate of the spherical coordinates given the p, theta and z of cylindrical coord...
scalar_unit spherical_to_cartesian_3d_x(const scalar_unit &r, const angle &theta, const angle &phi)
Returns the x coordinate of the cartesian coordinates in 3D given the r, theta and phi of spherical c...
scalar_unit cylindrical_to_cartesian_3d_z(const scalar_unit &p, const angle &theta, const scalar_unit &z)
Returns the z coordinate of the cartesian coordinates in 3D given the p, theta and z of cylindrical c...
angle cylindrical_to_spherical_theta(const scalar_unit &p, const angle &theta, const scalar_unit &z)
Returns the theta coordinate of the spherical coordinates given the p, theta and z of cylindrical coo...
angle cartesian_3d_to_spherical_phi(const scalar_unit &x, scalar_unit y, scalar_unit z)
Returns the phi coordinate of the spherical coordinates given the x, y and z of cartesian coordinates...
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
const scalar_unit WGS84_EARTH_SEMIAXIS_B
Definition constants.cpp:10
bool is_angle(const string &init_angle)
Checks if some string is an initialization string of an angle.
Definition angle.cpp:336
const scalar_unit WGS84_EARTH_SEMIAXIS_A
Definition constants.cpp:9