1#ifndef SCIFIR_UNITS_COORDINATES_COORDINATES_3D_HPP_INCLUDED
2#define SCIFIR_UNITS_COORDINATES_COORDINATES_3D_HPP_INCLUDED
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"
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);
32 scalar_unit P =
F/(3.0f * std::pow(
k,2) *
scalar_unit(std::pow(
G,2),{
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR) }));
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);
55 scalar_unit P =
F/(3.0f * std::pow(
k,2) *
scalar_unit(std::pow(
G,2),{
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR),
dimension(
dimension::METRE,
prefix::NONE,
dimension::NUMERATOR) }));
65 long double e_square = 0.00669437999014l;
73 long double e_square = 0.00669437999014l;
81 long double e_square = 0.00669437999014l;
91 long double p = std::sqrt(std::pow(x,2) + std::pow(y,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));
114 long double p = std::sqrt(std::pow(x,2) + std::pow(y,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));
128 template<
typename T = length>
340 out <<
"(" <<
x <<
"," <<
y <<
"," <<
z <<
")";
382 if (values.size() == 3)
390 cout <<
"values[0]: " << values[0] <<
endl;
391 cout <<
"values[1]: " << values[1] <<
endl;
392 cout <<
"values[2]: " << values[2] <<
endl;
502 return float(std::sqrt(std::pow(
x,2) + std::pow(
y,2)));
512 return float(std::sqrt(std::pow(
x,2) + std::pow(
y,2) + std::pow(
z,2)));
617 return float(std::sqrt(std::pow(
x,2) + std::pow(
y,2) + std::pow(
z,2)));
665 if (values.size() == 3)
667 if (values[0] ==
"" or values[1] ==
"" or values[2] ==
"")
714 string to_string(
const coordinates_3d<float>& x);
718 template<
typename T,
typename U>
724 float distance(
const coordinates_3d<float>& x,
const coordinates_3d<float>& y);
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)))));
811 return scalar_unit(std::sqrt(std::pow(
float(
p),2) + std::pow(
float(z),2)),
p.get_dimensions());
827 return float(std::sqrt(std::pow(x,2) + std::pow(y,2)));
842 return float(std::sqrt(std::pow(x,2) + std::pow(y,2) + std::pow(z,2)));
902 return float(std::sqrt(std::pow(
p,2) + std::pow(z,2)));
916template<
typename T,
typename U>
919 if (x.
x == y.
x and x.y == y.y and x.z == y.z)
929template<
typename T,
typename U>
945 return !(x == init_coordinates_3d);
958 return !(init_coordinates_3d == x);
970 return x + to_string(y);
976 return to_string(x) + y;
982 return os << to_string(x);
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
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,...
@ NUMERATOR
The dimension is at the numerator.
@ METRE
Meter, plural meters. SI dimension of length. Symbol m.
@ NONE
There is no prefix. Then, the dimension is not increased or decreased by some factor.
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.
cardinale_point create_cardinale_point(const string &x)
bool is_latitude(const string &init_latitude)
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++,...
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+...
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.
angle atan2(float y, float x)
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.
string display_float(const float &value, int number_of_decimals)
float acos_degree(float x)
Calculates the acos receiving x in degrees. It uses the acos() function of the standard library of C+...
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++,...
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
const scalar_unit WGS84_EARTH_SEMIAXIS_B
bool is_angle(const string &init_angle)
Checks if some string is an initialization string of an angle.
const scalar_unit WGS84_EARTH_SEMIAXIS_A