I'm currently working on a project in python that aim to plot the trajectory of an asteroid in the solar system and see how a specific impact can change it's trajectory.
After searching the subject, I came accros the concept of orbital elements. So I created a code that take in parameter:
- the Semimajor axis (AU)
- the Orbital eccentricity
- the Orbital inclination (deg)
- the Longitude of ascending node (deg)
- Longitude of perihelion (deg)
This information is stored in a dictionnary such as:
dic_planetary_datasheet = { 'Mercure': { 'a': 0.38709893, 'e': 0.20563069, 'i': 7.00487, 'w': 77.45645, 'omega': 48.33167, 'color': 'indianred' }, 'Venus': { 'a': 0.72333199, 'e': 0.00677323, 'i': 3.39471, 'w': 131.53298, 'omega': 76.68069, 'color': 'wheat' }, 'Terre': { 'a': 1.00000011, 'e': 0.01671022, 'i': 0.00005, 'w': 102.94719, 'omega': -11.26064, 'color': 'cornflowerblue' }, 'Mars': { 'a': 1.52366231, 'e': 0.09341233, 'i': 1.85061, 'w': 336.04084, 'omega': 49.57854, 'color': "sandybrown" } }```
I already checked on different website for the value and they seem correct. I then convert this information to cartesian-heliocentric coordinates and I plot the result:
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits import mplot3d AU = 149597870.7 # astronomical unit [km] G = 6.67428e-11 # Newtonian constant of gravitation [m^3*kg^-1*s^-2] M_soleil = 1.9884e30 # solar mass [kg] mu = G * M_soleil # standard gravitational parameter [m^3*s^-2] def from_DEG_to_RAD(deg_value): return ((deg_value * np.pi)/180) def convert_KOP_to_cartesian(a, e, i, omega, w): ''' Convert from keplerian orbital object param. to cartesian state vector for 1 revolution :param a: Semi-major axis [AU] -> [km] :param e: Eccentricity [1] :param i: Inclination [deg] -> [rad] :param omega: Longitude of ascending node (LAN) [deg] -> [rad] :param w: Argument of perihelion [deg] -> [rad] :return: x, y, z (Cartesian coordinates in km) ''' a_km = a*AU num_points = 10000 x = [] y = [] z = [] x_p = np.zeros(num_points) y_p = np.zeros(num_points) z_p = np.zeros(num_points) i_rad = from_DEG_to_RAD(i) w_rad = from_DEG_to_RAD(w) omega_rad = from_DEG_to_RAD(omega) n = np.sqrt(mu/a_km**3) for M in np.linspace(0, 2 * np.pi, num_points): E = M for _ in range(100): # Méthode itérative de Newton-Raphson E = E - (E - e * np.sin(E) - M) / (1.0 - e * np.cos(E)) nu = 2*np.arctan(np.sqrt((1.0 + e)/(1.0 - e))*np.tan(E/2.0)) h = np.sqrt(mu * a_km * (1 - e ** 2)) r = a_km * (1 - e * np.cos(E)) x.append( r*( np.cos(w_rad)*np.cos(nu+omega_rad) - np.sin(w_rad)*np.sin(nu+omega_rad)*np.cos(i_rad) ) ) y.append( r*( np.sin(w_rad)*np.cos(nu+omega_rad) + np.cos(w_rad)*np.sin(nu+omega_rad)*np.cos(i_rad) ) ) z.append( r*( np.sin(nu+omega_rad)*np.sin(i_rad) ) ) return x, y, z def plot_orbit_KOE_other_YR4(dic_planetary_datasheet): for planet, KOE in dic_planetary_datasheet.items(): x, y, z = convert_KOP_to_cartesian(KOE['a'], KOE['e'], KOE['i'], KOE['omega'], KOE['w']) ax.plot3D(x, y, z, label=f'Trajectoire {planet}', color=KOE['color']) #asteroid trajectory x_a, y_a, z_a = convert_KOP_to_cartesian(2.516, 0.6615, 3.408, 134.36, 271.37) fig = plt.figure() ax = plt.axes(projection='3d') ax.scatter(0,0,0, label='Soleil', color='yellow', marker='o') ax.plot3D(x_a, y_a, z_a, label=f'2024 YR4', color = 'black') plot_orbit_KOE_other_YR4(dic_planetary_datasheet) ax.set_title('3D trajectories (KOE method)') plt.show()
The problem is I get very big angle between all the trajectory and after searching I can't find a solution to that. I compared it with JPL simulation and they only have a few degrees in differences... My result using this code: JPL simulation result
If someone can help me with that it would be lovely !
Ps: If anyone know, can we get the same result(with angles and elliptic orbit) using newton method to solve a system of equations based on Netwon Gravitational Law because I only get spherical and plane trajectory