#define _USE_MATH_DEFINES #include "orbit.h" Orbit::Orbit(elements_orbit input_elements) : m_elements{ input_elements } { calculate_const_elements_ellipse(); log_coordinates.open("log_coordinates.txt"); log_coordinates << m_elements << "\n--------------------------------\n" << m_const_ellipse << "\n--------------------------------\n"; }; int Orbit::calculate_E(int accuracy) { double epsilon = 1 * pow(10, -accuracy); double buffer_Ek = m_variable_ellipse.M; double buffer_Ek1 = 0; while (std::abs(buffer_Ek1 - buffer_Ek) > epsilon) { buffer_Ek1 = m_variable_ellipse.M + m_elements.e * sin(buffer_Ek); buffer_Ek = buffer_Ek1; } m_variable_ellipse.E = buffer_Ek; return 1; } int Orbit::calculate_const_elements_ellipse() { m_const_ellipse.r_p = m_elements.p / (1 + m_elements.e); m_const_ellipse.r_a = m_elements.p / (1 - m_elements.e); m_const_ellipse.a = (m_const_ellipse.r_p + m_const_ellipse.r_a) / 2; m_const_ellipse.b = sqrt(m_const_ellipse.r_p + m_const_ellipse.r_a); m_const_ellipse.abs_c = sqrt(m_elements.p * gravitational_parameter_Earth); m_const_ellipse.n = sqrt(gravitational_parameter_Earth / pow(m_const_ellipse.a, 3)); m_const_ellipse.T = 2 * M_PI * sqrt(pow(m_const_ellipse.a, 3) / gravitational_parameter_Earth); return 1; } int Orbit::calculate_varible_elements_ellipse(double current_time) { log_coordinates << std::setprecision(20) << current_time << "\n"; m_variable_ellipse.M = m_const_ellipse.n * (current_time - m_elements.tau); calculate_E(4); m_variable_ellipse.nu = 2 * atan(sqrt((1 + m_elements.e) / (1 + m_elements.e)) * tan(m_variable_ellipse.E / 2)); m_variable_ellipse.r = m_elements.p / (1 + m_elements.e * cos(m_variable_ellipse.nu)); m_variable_ellipse.u = m_elements.omega + m_variable_ellipse.nu; m_variable_ellipse.Vr= sqrt(gravitational_parameter_Earth * m_elements.p) * m_elements.e * sin(m_variable_ellipse.nu); m_variable_ellipse.dnu = m_const_ellipse.abs_c / pow(m_variable_ellipse.r, 2); return 1; } int Orbit::calculate_coordinates() { m_coordinates.x = m_variable_ellipse.r * (cos(m_variable_ellipse.u) * cos(m_elements.precession) - sin(m_variable_ellipse.u) * sin(m_elements.precession) * cos(m_elements.nutation)); m_coordinates.y = m_variable_ellipse.r * (cos(m_variable_ellipse.u) * sin(m_elements.precession) + sin(m_variable_ellipse.u) * cos(m_elements.precession) * cos(m_elements.nutation)); m_coordinates.z = m_variable_ellipse.r * sin(m_variable_ellipse.u) * sin(m_elements.nutation); return 0; } int Orbit::calculate_speed_components() { m_speed_components.v_x = m_variable_ellipse.Vr * m_coordinates.x / m_variable_ellipse.r - m_variable_ellipse.r * (sin(m_variable_ellipse.u) * cos(m_elements.precession) + cos(m_variable_ellipse.u) * sin(m_elements.precession) * cos(m_elements.nutation))*m_variable_ellipse.dnu; m_speed_components.v_y = m_variable_ellipse.Vr * m_coordinates.y / m_variable_ellipse.r - m_variable_ellipse.r * (sin(m_variable_ellipse.u) * sin(m_elements.precession) - cos(m_variable_ellipse.u) * cos(m_elements.precession) * cos(m_elements.nutation)) * m_variable_ellipse.dnu; m_speed_components.v_z = m_variable_ellipse.Vr * m_coordinates.z / m_variable_ellipse.r + m_variable_ellipse.r * cos(m_variable_ellipse.u) * sin(m_elements.nutation) * m_variable_ellipse.dnu; return 0; } int Orbit::modulation() { calculate_varible_elements_ellipse(m_time.getCurrent_UNIX()); calculate_coordinates(); calculate_speed_components(); log_coordinates << m_coordinates << "\n" << m_speed_components << "\n--------------------------------\n"; return 0; } std::ostream& operator<<(std::ostream& out, const elements_orbit& i_elements_orbit) { out << "Focal parameter = " << i_elements_orbit.p << " || " << "eccentricity of the orbit = " << i_elements_orbit.e << " || " << "longitude of the ascending node = " << i_elements_orbit.precession << "\n" << "inclination of the orbit = " << i_elements_orbit.nutation << " || " << "the perigee latitude argument" << i_elements_orbit.omega << " || " << "tau = "<< i_elements_orbit.tau; return out; } std::ofstream& operator<<(std::ofstream& out, const elements_orbit& i_elements_orbit) { out << "Focal parameter = " << i_elements_orbit.p << " || " << "eccentricity of the orbit = " << i_elements_orbit.e << " || " << "longitude of the ascending node = " << i_elements_orbit.precession << "\n" << "inclination of the orbit = " << i_elements_orbit.nutation << " || " << "the perigee latitude argument" << i_elements_orbit.omega << " || " << "tau = " << i_elements_orbit.tau; return out; } std::ostream& operator <<(std::ostream& out, const const_elements_ellipse_orbite& i_const_elements_ellipse_orbite) { out << "Smallest distance = " << i_const_elements_ellipse_orbite.r_p << " || " << "the largest distance = " << i_const_elements_ellipse_orbite.r_a << " || " << "major semiaxis = " << i_const_elements_ellipse_orbite.a << "\n" << "minor semiaxis = " << i_const_elements_ellipse_orbite.b << " || " << "constant vector of areas = " << i_const_elements_ellipse_orbite.abs_c << " || " << "constant angular velocity" << i_const_elements_ellipse_orbite.n << "\n" << "orbit period" << i_const_elements_ellipse_orbite.T; return out; } std::ofstream& operator <<(std::ofstream& out, const const_elements_ellipse_orbite& i_const_elements_ellipse_orbite) { out << "Smallest distance = " << i_const_elements_ellipse_orbite.r_p << " || " << "the largest distance = " << i_const_elements_ellipse_orbite.r_a << " || " << "major semiaxis = " << i_const_elements_ellipse_orbite.a << "\n" << "minor semiaxis = " << i_const_elements_ellipse_orbite.b << " || " << "constant vector of areas = " << i_const_elements_ellipse_orbite.abs_c << " || " << "constant angular velocity" << i_const_elements_ellipse_orbite.n << "\n" << "orbit period" << i_const_elements_ellipse_orbite.T; return out; } std::ostream& operator <<(std::ostream& out, const variable_elements_ellipse_orbit& i_variable_elements_ellipse_orbit) { out << "Average anomaly = " << i_variable_elements_ellipse_orbit.M << " || " << "Eccentric anomaly = " << i_variable_elements_ellipse_orbit.E << " || " << "True anomaly = " << i_variable_elements_ellipse_orbit.nu << " || " << "radius-vector" << i_variable_elements_ellipse_orbit.r << "\n" << "satellite latitude argument = " << i_variable_elements_ellipse_orbit.u << " || " << "angular velocity = " << i_variable_elements_ellipse_orbit.dnu << " || " << "radial velocity projection = " << i_variable_elements_ellipse_orbit.Vr; return out; } std::ofstream& operator <<(std::ofstream& out, const variable_elements_ellipse_orbit& i_variable_elements_ellipse_orbit) { out << "Average anomaly = " << i_variable_elements_ellipse_orbit.M << " || " << "Eccentric anomaly = " << i_variable_elements_ellipse_orbit.E << " || " << "True anomaly = " << i_variable_elements_ellipse_orbit.nu << " || " << "radius-vector" << i_variable_elements_ellipse_orbit.r << "\n" << "satellite latitude argument = " << i_variable_elements_ellipse_orbit.u << " || " << "angular velocity = " << i_variable_elements_ellipse_orbit.dnu << " || " << "radial velocity projection = " << i_variable_elements_ellipse_orbit.Vr; return out; } std::ostream& operator <<(std::ostream& out, const coordinates& i_coordinates) { out << "x = " << i_coordinates.x << " || " << "y = " << i_coordinates.y << " || " << "z = " << i_coordinates.z; return out; } std::ofstream& operator <<(std::ofstream& out, const coordinates& i_coordinates) { out << "x = " << i_coordinates.x << " || " << "y = " << i_coordinates.y << " || " << "z = " << i_coordinates.z; return out; } std::ostream& operator <<(std::ostream& out, const speed_components& i_speed_components) { out << "V_x = " << i_speed_components.v_x << " || " << "V_y = " << i_speed_components.v_y << " || " << "V_z = " << i_speed_components.v_z; return out; }; std::ofstream& operator <<(std::ofstream& out, const speed_components& i_speed_components) { out << "V_x = " << i_speed_components.v_x << " || " << "V_y = " << i_speed_components.v_y << " || " << "V_z = " << i_speed_components.v_z; return out; }; std::ostream& operator <<(std::ostream& out, const Orbit& out_orbit) { out << "elements_orbit\n" << out_orbit.m_elements << "\n--------------------------------\n" << "const_elements_ellipse_orbite\n" << out_orbit.m_const_ellipse << "\n--------------------------------\n" << "variable_elements_ellipse_orbit\n" << out_orbit.m_variable_ellipse << "\n--------------------------------\n"; return out; }; std::ofstream& operator <<(std::ofstream& out, const Orbit& out_orbit) { out << "elements_orbit\n" << out_orbit.m_elements << "\n--------------------------------\n" << "const_elements_ellipse_orbite\n" << out_orbit.m_const_ellipse << "\n--------------------------------\n" << "variable_elements_ellipse_orbit\n" << out_orbit.m_variable_ellipse << "\n--------------------------------\n"; return out; };