From f962857df86a406b509c660a8d1352163cdcc551 Mon Sep 17 00:00:00 2001 From: iamlrk Date: Sun, 5 Mar 2023 11:44:44 +0530 Subject: [PATCH] added plot_orbit feature plot multiple orbits in the same graph --- .idea/.gitignore | 3 + .idea/MOPy.iml | 10 + .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + mopylib/constants/planetarydetails.py | 4 +- mopylib/orbitalparameters.py | 197 ++++++++++-------- mopylib/orbitplot.py | 136 ++++++++---- mopylib/temp_stor/orbit3d.py | 10 +- mopylib/test.py | 75 +++---- 11 files changed, 284 insertions(+), 175 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/MOPy.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/MOPy.iml b/.idea/MOPy.iml new file mode 100644 index 0000000..2c80e12 --- /dev/null +++ b/.idea/MOPy.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..ac35dca --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..332b615 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/mopylib/constants/planetarydetails.py b/mopylib/constants/planetarydetails.py index 29745b4..d21a0e7 100644 --- a/mopylib/constants/planetarydetails.py +++ b/mopylib/constants/planetarydetails.py @@ -163,9 +163,9 @@ def split_unit(input_unit): angle - radians, degrees, rad, deg SI Prefix = ['Y', 'Z', 'E', 'P', 'T', 'G', 'M', 'K', 'H', 'D', 'd', 'c', 'm', 'u', 'n', 'p', 'f', 'a', 'z'] """ - if unit[0][0] in SIV.SI_PREFIX: + if unit[0][0] in SI_PREFIX: if unit[1] > 0: - units_calculation.append(SIV.SI_PREFIX_VALUES[unit[0][0]]) + units_calculation.append(SI_PREFIX_VALUES[unit[0][0]]) elif unit[1] < 0: pass # units_calculation.append(1/(SIV.SI_PREFIX_VALUES[unit[0][0]])) diff --git a/mopylib/orbitalparameters.py b/mopylib/orbitalparameters.py index 27b9eb4..7c6645f 100644 --- a/mopylib/orbitalparameters.py +++ b/mopylib/orbitalparameters.py @@ -2,150 +2,163 @@ import constants.GlobalConstants as GCs import constants.planetarydetails as pandet -class OrbitalValues(): + +class OrbitalValues: """The initiate the variables and calculate all the rest of the values related to the orbit based on the input. - This take the given inputs and evaluates if the given information is enough to calculate the all the required orbital values. - If not, it will return an error. + This take the given inputs and evaluates if the given information is enough to calculate the all the required + orbital values. If not, it will return an error. ### !!! Enter any of the two values only to avoid over constrained situation!!! - - If it does you can calculate other operations in this class. + ------ Example: - >>> `import mopylib.orbitalparameters as orbit_par - >>> `orbit_1 = orbit_par.OrbitalValues("Earth", semi_major_axis=20000, eccentricity=0.4)` - >>> `orbit_1_values = orbit_1.caculate_orbital_values()` - >>> `print(orbit_1_values)` + >>> import mopylib.orbitalparameters as orbit_par + >>> orbit_01 = orbit_par.OrbitalValues("Earth", semi_major_axis=20000, eccentricity=0.4) + >>> orbit_01_values = orbit_1.calculate_orbital_values() + >>> print(orbit_01_values) Output: - >>> `{'SemiMajorAxis': 20000, 'Eccentricity': 0.4, 'RadiusOfPerigee': 12000.0, + >>> {'SemiMajorAxis': 20000, 'Eccentricity': 0.4, 'RadiusOfPerigee': 12000.0, 'RadiusOfApogee': 28000.0, 'MeanMotion': 4480.043512802378, 'TimePeriod': 28148.943575165125, 'SpecificAngularMomentum': 81830.91404108841, 'SpecificMechanicalEnergy': -9.9647299, 'SemiLatusRectum': 16800.0}` ------ Args: major_body (String): Name of the Major Body of the Orbit - radiusOfApogee (float, optional): Radius of Apogee of the Orbit. Defaults to None. - radiusOfPerigee (float, optional): Radius of Perigee of the Orbit. Defaults to None. + radius_of_apogee (float, optional): Radius of Apogee of the Orbit. Defaults to None. + radius_of_perigee (float, optional): Radius of Perigee of the Orbit. Defaults to None. semi_major_axis (float, optional): Semi Major Axis of the Orbit. Defaults to None. eccentricity (Float, optional): Eccentricity of the Orbit. Defaults to None. """ - def __init__(self, major_body, - radius_of_apogee=None, - radius_of_perigee=None, - semi_major_axis=None, + + def __init__(self, major_body, + radius_of_apogee=None, + radius_of_perigee=None, + semi_major_axis=None, eccentricity=None): + self.specific_mechanical_energy = None + self.mean_motion = None + self.orbital_time_period = None + self.specific_angular_momentum = None + self.semi_latus_rectum = None + self.gravitational_constant = None self.major_body = major_body self.major_body_mass = pandet.value(major_body, 'mass') self.radius_of_apogee = radius_of_apogee self.radius_of_perigee = radius_of_perigee self.semi_major_axis = semi_major_axis self.eccentricity = eccentricity - OrbitalValues.calculate_rest(self) - + self.calculate_rest() + def calculate_orbital_constants(self): self.gravitational_constant = GCs.NEWTON_GRAVITATIONAL_CONSTANT * self.major_body_mass - self.semi_latus_rectum = self.semi_major_axis*(1-self.eccentricity**2) - self.specific_angular_momentum = (self.radius_of_perigee*(1+self.eccentricity)*self.gravitational_constant)**0.5 - self.orbital_time_period = np.sqrt(((4*np.pi**2)/self.gravitational_constant)*self.semi_major_axis**3) - self.mean_motion = self.orbital_time_period/(2*np.pi) - self.specific_mechanical_energy = -self.gravitational_constant/(2* self.semi_major_axis) - return self.mean_motion, self.orbital_time_period, self.specific_angular_momentum, self.specific_mechanical_energy, self.semi_latus_rectum - + self.semi_latus_rectum = self.semi_major_axis * (1 - self.eccentricity ** 2) + self.specific_angular_momentum = (self.radius_of_perigee * ( + 1 + self.eccentricity) * self.gravitational_constant) ** 0.5 + self.orbital_time_period = np.sqrt(((4 * np.pi ** 2) / self.gravitational_constant) * self.semi_major_axis ** 3) + self.mean_motion = self.orbital_time_period / (2 * np.pi) + self.specific_mechanical_energy = -self.gravitational_constant / (2 * self.semi_major_axis) + return self.mean_motion, self.orbital_time_period, self.specific_angular_momentum, \ + self.specific_mechanical_energy, self.semi_latus_rectum + def calculate_rest(self): - if self.radius_of_apogee and self.radius_of_perigee != None: - self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee)/2 - self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee)/ \ + if self.radius_of_apogee and self.radius_of_perigee is not None: + self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee) / 2 + self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee) / \ (self.radius_of_apogee + self.radius_of_perigee) - elif self.semi_major_axis and self.eccentricity != None: + elif self.semi_major_axis and self.eccentricity is not None: self.radius_of_perigee = self.semi_major_axis * (1 - self.eccentricity) - self.radius_of_apogee = self.semi_major_axis * (1 + self.eccentricity) - - elif self.semi_major_axis and self.radius_of_apogee != None: - self.radius_of_perigee = 2*self.semi_major_axis - self.radius_of_apogee - self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee)/ \ + self.radius_of_apogee = self.semi_major_axis * (1 + self.eccentricity) + + elif self.semi_major_axis and self.radius_of_apogee is not None: + self.radius_of_perigee = 2 * self.semi_major_axis - self.radius_of_apogee + self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee) / \ (self.radius_of_apogee + self.radius_of_perigee) - elif self.semi_major_axis and self.radius_of_perigee != None: - self.radius_of_apogee = 2*self.semi_major_axis - self.radius_of_perigee - self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee)/ \ + elif self.semi_major_axis and self.radius_of_perigee is not None: + self.radius_of_apogee = 2 * self.semi_major_axis - self.radius_of_perigee + self.eccentricity = (self.radius_of_apogee - self.radius_of_perigee) / \ (self.radius_of_apogee + self.radius_of_perigee) - elif self.eccentricity and self.radius_of_apogee != None: - self.radius_of_perigee = self.radius_of_apogee * ((1 - self.eccentricity)/(1 + self.eccentricity)) - self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee)/2 - elif self.eccentricity and self.radius_of_perigee != None: - self.radius_of_apogee = self.radius_of_perigee * ((1 + self.eccentricity)/(1 - self.eccentricity)) - self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee)/2 - - OrbitalValues.calculate_orbital_constants(self) - - def caculate_orbital_values(self, return_style='dict'): + elif self.eccentricity and self.radius_of_apogee is not None: + self.radius_of_perigee = self.radius_of_apogee * ((1 - self.eccentricity) / (1 + self.eccentricity)) + self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee) / 2 + elif self.eccentricity and self.radius_of_perigee is not None: + self.radius_of_apogee = self.radius_of_perigee * ((1 + self.eccentricity) / (1 - self.eccentricity)) + self.semi_major_axis = (self.radius_of_perigee + self.radius_of_apogee) / 2 + + self.calculate_orbital_constants() + + def calculate_orbital_values(self, return_style='dict'): # possible values dict(default), variables if return_style == 'dict': orbital_values = { - "SemiMajorAxis": self.semi_major_axis, "Eccentricity": self.eccentricity, - "RadiusOfPerigee": self.radius_of_perigee, "RadiusOfApogee": self.radius_of_apogee, - "MeanMotion": self.mean_motion, "TimePeriod": self.orbital_time_period, - "SpecificAngularMomentum": self.specific_angular_momentum, "SpecificMechanicalEnergy":self.specific_mechanical_energy, - "SemiLatusRectum": self.semi_latus_rectum - } + "SemiMajorAxis": self.semi_major_axis, "Eccentricity": self.eccentricity, + "RadiusOfPerigee": self.radius_of_perigee, "RadiusOfApogee": self.radius_of_apogee, + "MeanMotion": self.mean_motion, "TimePeriod": self.orbital_time_period, + "SpecificAngularMomentum": self.specific_angular_momentum, + "SpecificMechanicalEnergy": self.specific_mechanical_energy, + "SemiLatusRectum": self.semi_latus_rectum + } return orbital_values elif return_style == 'variables': return self.semi_major_axis, self.eccentricity, self.radius_of_perigee, self.radius_of_apogee, \ - self.mean_motion, self.orbital_time_period, self.specific_angular_momentum, self.specific_mechanical_energy, \ - self.semi_latus_rectum - + self.mean_motion, self.orbital_time_period, self.specific_angular_momentum, self.specific_mechanical_energy, \ + self.semi_latus_rectum + def calculate_velocities_at_these_angles(self, *angles): velocities = [] for angle in angles: velocities.append(OrbitalValues.calculate_velocity_at_point(self, angle=angle)) return velocities - + def calculate_velocities_at_these_points(self, *radii): velocities = [] for radius in radii: velocities.append(OrbitalValues.calculate_velocity_at_point(self, radius=radius)) return velocities - - def calculate_velocity_at_point(self, radius=None,angle=None): - if angle != None: - radius = ((self.specific_angular_momentum**2/self.gravitational_constant)/(1+(self.eccentricity)*np.cos(angle))) - velocity = np.sqrt((2*self.gravitational_constant/radius)-(self.gravitational_constant/self.semi_major_axis)) + def calculate_velocity_at_point(self, radius=None, angle=None): + if angle is not None: + radius = ((self.specific_angular_momentum ** 2 / self.gravitational_constant) / ( + 1 + self.eccentricity * np.cos(angle))) + + velocity = np.sqrt( + (2 * self.gravitational_constant / radius) - (self.gravitational_constant / self.semi_major_axis)) return velocity + if __name__ == '__main__': import pandas as pd + + sma = np.linspace(7000, 100000, num=15) + e = np.linspace(0, 1, num=15, endpoint=False) # test = OrbitalValues("Earth", radiusOfApogee = 20000, radiusOfPerigee = 10000) # orbit_1 = OrbitalValues("Earth", semi_major_axis=20000, eccentricity=0) - orbit_1 = OrbitalValues("Earth", semi_major_axis=20000, eccentricity=0.4) - orbit_2 = OrbitalValues("Earth", semi_major_axis=20000, radius_of_apogee=28000) - orbit_3 = OrbitalValues("Earth", semi_major_axis=20000, radius_of_perigee=12000) - orbit_4 = OrbitalValues("Earth", eccentricity=0.4, radius_of_apogee=28000) - orbit_5 = OrbitalValues("Earth", eccentricity=0.4, radius_of_perigee=12000) - orbit_6 = OrbitalValues("Earth", radius_of_perigee=12000, radius_of_apogee=28000) - orbital_values = [ - orbit_1.caculate_orbital_values(), - orbit_2.caculate_orbital_values(), - orbit_3.caculate_orbital_values(), - orbit_4.caculate_orbital_values(), - orbit_5.caculate_orbital_values(), - orbit_6.caculate_orbital_values() - ] - - # orbital_values = [orbit_1.caculate_orbital_values()] - orbital_values_df = pd.DataFrame.from_dict(orbital_values) - # pd.set_option('display.max_columns', None) - # orbital_values_df.head() - print(orbital_values_df.T) - print(orbital_values[0]) - - - - - - print(orbit_1.calculate_velocities_at_these_angles(0,np.pi/2,np.pi)) - - - \ No newline at end of file + # orbit_1 = OrbitalValues("Earth", semi_major_axis=20000, eccentricity=0.4) + # orbit_2 = OrbitalValues("Earth", semi_major_axis=20000, radius_of_apogee=28000) + # orbit_3 = OrbitalValues("Earth", semi_major_axis=20000, radius_of_perigee=12000) + # orbit_4 = OrbitalValues("Earth", eccentricity=0.4, radius_of_apogee=28000) + # orbit_5 = OrbitalValues("Earth", eccentricity=0.4, radius_of_perigee=12000) + # orbit_6 = OrbitalValues("Earth", radius_of_perigee=12000, radius_of_apogee=28000) + for i, j in zip(sma, e): + orbit_1 = OrbitalValues("Earth", semi_major_axis=i, eccentricity=j) + print(f'{orbit_1.calculate_orbital_values()} \n') + + # orbital_values = [ + # orbit_1.calculate_orbital_values(), + # # orbit_2.calculate_orbital_values(), + # # orbit_3.calculate_orbital_values(), + # # orbit_4.calculate_orbital_values(), + # # orbit_5.calculate_orbital_values(), + # # orbit_6.calculate_orbital_values() + # ] + + # orbital_values = [orbit_1.calculate_orbital_values()] + # orbital_values_df = pd.DataFrame.from_dict(orbital_values) + # # pd.set_option('display.max_columns', None) + # # orbital_values_df.head() + # print(orbital_values_df.T) + # print(orbital_values[0]) + + print(orbit_1.calculate_velocities_at_these_angles(0, np.pi / 2, np.pi)) diff --git a/mopylib/orbitplot.py b/mopylib/orbitplot.py index e4779f3..76bdc2d 100644 --- a/mopylib/orbitplot.py +++ b/mopylib/orbitplot.py @@ -5,58 +5,116 @@ import constants.GlobalConstants as GCs -class plotter(): - def __init__(self, major_body, - radius_of_apogee=None, - radius_of_perigee=None, - semi_major_axis=None, - eccentricity=None, - start_end_angle=[0, 2*np.pi], - orbit_resolution=1000): +class Plotter: + """ + orbitss = {'orbit_1': { + 'radius_of_apogee': 125, 'radius_of_perigee': 00000, + 'semi_major_axis': 00000, 'eccentricity': 00000, + 'start_end_angle':[0, 2], 'orbit_resolution':1000 + } + } + """ + def __init__(self, orbit_ax, major_body, + radius_of_apogee=None, + radius_of_perigee=None, + semi_major_axis=None, + eccentricity=None, + start_end_angle=None, + orbit_resolution=1000, + **entered_orbits): + if start_end_angle is None: + start_end_angle = [0, 2 * np.pi] + self.major_body_color = None + self.y_coordinates = None + self.x_coordinates = None + self.ax = orbit_ax self.major_body = major_body self.major_body_mass = pandet.value(major_body, 'mass') self.gravitational_constant = GCs.NEWTON_GRAVITATIONAL_CONSTANT * self.major_body_mass + self.plot_details = {} # {'orbit_0' : {'start_angle': 00, 'end_angle': 11, 'orbit_resolution': 0000}, ....} + self.all_orbits, self.orbit_name = Plotter.divide_the_orbits(**entered_orbits) + self.all_orbital_values = {} + for orbit_no, orbit in self.all_orbits.items(): + self.plot_details[orbit_no] = {'start_angle': orbit.get('start_angle', 0), 'end_angle': orbit.get('end_angle', (2*np.pi)), 'orbit_resolution': orbit.get('orbit_resolution', 1000)} + orbital_values = OrbitalValues(self.major_body, orbit.get('radius_of_apogee', None), + orbit.get('radius_of_perigee', None), orbit.get('semi_major_axis', None), + orbit.get('eccentricity', None)) + self.all_orbital_values[orbit_no] = orbital_values.calculate_orbital_values() + + self.radius_of_apogee = radius_of_apogee self.radius_of_perigee = radius_of_perigee self.semi_major_axis = semi_major_axis self.eccentricity = eccentricity - self.orbital_values = OrbitalValues(self.major_body, self.radius_of_apogee, - self.radius_of_perigee, - self.semi_major_axis, - self.eccentricity) - self.orbital_values_dict = self.orbital_values.caculate_orbital_values() + self.orbital_values = OrbitalValues(self.major_body, self.radius_of_apogee, + self.radius_of_perigee, + self.semi_major_axis, + self.eccentricity) + self.orbital_values_dict = self.orbital_values.calculate_orbital_values() self.start_angle, self.end_angle = start_end_angle[0], start_end_angle[1] self.orbit_resolution = orbit_resolution - def get_orbit_plot_points(self): - theta = np.linspace(self.start_angle, self.end_angle, self.orbit_resolution) - radii_points=(self.orbital_values_dict['SpecificAngularMomentum']**2/\ - self.gravitational_constant)/(1+self.orbital_values_dict['Eccentricity']*np.cos(theta)) - self.x_coordinates = radii_points*np.sin(theta) - self.y_coordinates = radii_points*np.cos(theta) - - def plot_orbit(self, show_body=True,show_orbit=True, **kwargs): - plotter.get_orbit_plot_points(self) - theta_body = np.linspace(0, 2*-np.pi, self.orbit_resolution) - theta_orbit = np.linspace(self.start_angle, self.end_angle, self.orbit_resolution) + def divide_the_orbits(**group_orbits): + all_orbits = {} + orbit_name = {} + for i,orbit in enumerate(group_orbits.items()): + all_orbits[f'orbit_{i}'] = orbit[1] + orbit_name[f'orbit_{i}'] = orbit[0] + + # for orbit_no, orbit in all_orbits.items(): + # try: + # check_value = orbit['start_end_angle'] + + # if orbit.get('start') - radius_of_body = pandet.value(self.major_body,'diameter')/2 - self.major_body_color = pandet.value(self.major_body, 'color') - plt.plot(self.x_coordinates, self.y_coordinates, **kwargs) + return all_orbits, orbit_name + + def get_orbit_plot_points(self, orbit_no): + _this_orbit_plot_details = self.plot_details.get(orbit_no) + _this_orbit_plot_values = self.all_orbital_values.get(orbit_no) + theta = np.linspace(_this_orbit_plot_details.get('start_angle'), _this_orbit_plot_details.get('end_angle'), _this_orbit_plot_details.get('orbit_resolution')) + radii_points = (_this_orbit_plot_values.get('SpecificAngularMomentum') ** 2 / + self.gravitational_constant) / (1 + _this_orbit_plot_values.get('Eccentricity') * np.cos(theta)) + x_coordinates = radii_points * np.sin(theta) + y_coordinates = radii_points * np.cos(theta) + return x_coordinates, y_coordinates + def plot_orbit(self, show_body=True, show_orbit=True, show_plot=True, **kwargs): + + radius_of_body = pandet.value(self.major_body, 'diameter') / 2 + theta_body = np.linspace(0, 2 * -np.pi, 1000) + self.major_body_color = pandet.value(self.major_body, 'color') + if show_body: - plt.fill(radius_of_body*np.sin(theta_body), radius_of_body*np.cos(theta_body), self.major_body_color) - ax = plt.gca() - ax.set_facecolor((0.0, 0.0, 0.0)) - ax.set_aspect('equal', adjustable='box') - plt.show() - # if show_orbit: - # plt.show() - + self.ax.fill(radius_of_body * np.sin(theta_body), radius_of_body * np.cos(theta_body), + self.major_body_color) + + + for orbit_no, orbit in self.all_orbital_values.items(): + _x, _y = self.get_orbit_plot_points(orbit_no) + if show_orbit: + ax.plot(_x, _y, **kwargs) + + if show_plot: + self.ax.set_facecolor((0.0, 0.0, 0.0)) + self.ax.set_aspect('equal', adjustable='box') + plt.show() + if __name__ == '__main__': - orbit_values = plotter('Earth', radius_of_apogee=25000, eccentricity=0.3, start_end_angle=[0, np.pi/2]) - orbit_values.plot_orbit(show_orbit=False, color='red') - orbit_values_2 = plotter('Earth', radius_of_apogee=25000, eccentricity=0.4, start_end_angle=[0, np.pi]) - orbit_values_2.plot_orbit(show_orbit=False, color='blue') \ No newline at end of file + orbitss = {'orbit_1': { + 'radius_of_apogee': 12000, 'radius_of_perigee': 20000, + 'semi_major_axis': None, 'eccentricity': None, + 'start_angle':0, 'end_angle': 2, 'orbit_resolution':1000 + }, + 'orbit_2': { + 'radius_of_apogee': 15000, 'radius_of_perigee': 7000 + } + } + + fig, ax = plt.subplots(1) + orbit_values = Plotter(ax, 'Earth', radius_of_apogee=25000, eccentricity=0.3, start_end_angle=[0, np.pi / 2], **orbitss) + orbit_values.plot_orbit(show_plot=True, color='red') + orbit_values_2 = Plotter(ax, 'Earth', radius_of_apogee=20000, eccentricity=0.4, start_end_angle=[0, np.pi]) + orbit_values_2.plot_orbit(show_plot=False, color='blue') diff --git a/mopylib/temp_stor/orbit3d.py b/mopylib/temp_stor/orbit3d.py index 4ce6ba0..874c4d9 100644 --- a/mopylib/temp_stor/orbit3d.py +++ b/mopylib/temp_stor/orbit3d.py @@ -111,7 +111,7 @@ def phasingManeuver(mu, rMB, ra1, rp1, thetaA, thetaB): # mMB = 5.9722e24 # a = OrbitPlot.plotOrbitMPL(3.986e5, rMB, ra, rp, mMB, 0, 2*np.pi) # # img = plt.imread("Functions/Assets/Models/hi_res_tex/stars.jpg") - # # fig, ax = plt.subplots() + # # fig, orbit_ax = plt.subplots() # # plt.imshow(img) # # plt.plot(a[0],a[1]) # theta = np.linspace(0, 2*np.pi, 500) @@ -119,8 +119,8 @@ def phasingManeuver(mu, rMB, ra1, rp1, thetaA, thetaB): # ry = 6378*np.cos(theta) # # plt.axes('equal') - # ax = plt.axes() - # ax.set_facecolor("black") - # ax.plot(rx, ry, color="white", linewidth=3) - # ax.axes('equal\') + # orbit_ax = plt.axes() + # orbit_ax.set_facecolor("black") + # orbit_ax.plot(rx, ry, color="white", linewidth=3) + # orbit_ax.axes('equal\') # plt.show() \ No newline at end of file diff --git a/mopylib/test.py b/mopylib/test.py index 5bbf792..bf30edf 100644 --- a/mopylib/test.py +++ b/mopylib/test.py @@ -1,37 +1,38 @@ -from pandac.PandaModules import * - -# Define the orbital parameters of the satellite -altitude = 500 # altitude of the satellite in kilometers -inclination = 30 # inclination of the satellite in degrees -eccentricity = 0.1 # eccentricity of the satellite - -# Compute the period of the satellite's orbit -G = 6.67 * 10**-11 # gravitational constant -Earth_radius = 6371 # radius of the Earth in kilometers -Earth_mass = 5.972 * 10**24 # mass of the Earth in kilograms -period = 2 * np.pi * np.sqrt( (altitude + Earth_radius)**3 / (G * Earth_mass) ) - -# Create a 3D scene -scene = NodePath("Scene") - -# Create a sphere to represent the Earth -earth = loader.loadModel("earth.bam") -earth.reparentTo(scene) -earth.setScale(1.0) - -# Create a model to represent the satellite -satellite = loader.loadModel("satellite.bam") -satellite.reparentTo(scene) - -# Propagate the satellite's orbit around the Earth -for i in range(0, int(period)): - # Compute the satellite's position using its orbital parameters - x = altitude * np.cos(i) - y = altitude * np.sin(i) * np.cos(inclination) - z = altitude * np.sin(i) * np.sin(inclination) - - # Update the satellite's position in the scene - satellite.setPos(x, y, z) - - # Update the scene - base.graphicsEngine.renderFrame() \ No newline at end of file +from types import SimpleNamespace + +def plot(**orbits): + all_orbits = {} + orbit_name = {} + for i,orbit in enumerate(orbits.items()): + print(orbit) + all_orbits[f'orbit_{i}'] = orbit[1] + orbit_name[f'orbit_{i}'] = orbit[0] + + # for key, value in all_orbits.items(): + # print(f'{key:10}> {value}') + return all_orbits, orbit_name + + +orbitss = {'orbit_1': { + 'radius_of_apogee': 125, 'radius_of_perigee': 00000, + 'semi_major_axis': 00000, 'eccentricity': 00000, + 'start_end_angle':[0, 2], 'orbit_resolution':1000 + }, + 'orbit_2': { + 'radius_of_apogee': 895, 'radius_of_perigee': 1111, + 'semi_major_axis': 13232, 'eccentricity': 1112, + 'start_end_angle':[0, 2], 'orbit_resolution':1000 + } + } + +# orbit_01 = { +# 'radius_of_apogee': 125, 'radius_of_perigee': 00000, +# 'semi_major_axis': 00000, 'eccentricity': 00000, +# 'start_end_angle':[0, 2], 'orbit_resolution':1000 +# } + +test_1, test_2 = plot(**orbitss) + +for orbit_no, orbit in test_1.items(): + print(orbit.get('radius_of_apogee')) + # print(test_1.get('orbit_0', None))