import numpy.linalg as lg import matplotlib.pyplot as plt import scipy.io as spio MU = 398600 RE = 6380 omega_earth = 2 * np.pi / 86164 f = 3.35e-3 # Orbit A init_cond = [7000, 0.01, 45, 0, -65, 0] theta_g_i = 0 t_0 = 0 P = 2 * np.pi * np.sqrt(init_cond[0]**3 / MU) # seconds print(P) [r_a, v_a] = sf.elm2cart(init_cond, MU) [r, v] = sf.orbit_prop_rk(r_a, v_a, t_0, P * 3, 60) time_series = np.arange(0, 3 * P, 60) step = 0 phi_gd = np.empty(np.shape(time_series)) lam = np.empty(np.shape(time_series)) for t_n in time_series: theta_g = theta_g_i + omega_earth * (t_n - t_0) r_ecf = np.matmul(sf.R3(theta_g), r[step, :]) r_norm = lg.norm(r_ecf) phi_gc = np.arcsin(r_ecf[2] / r_norm) lam[step] = np.arctan2(r_ecf[1], r_ecf[0]) phi_gd[step] = np.arctan2(np.tan(phi_gc), (1 - f)**2) step = step + 1 # Convert to degrees lam = np.multiply(lam, 180 / np.pi)
import space_functions as sf import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D elements = [70000, 0.01, 20, 180, 25, 0] r_0, v_0 = sf.elm2cart(elements, sf.earth.mu) T0 = 2451545.0 * 86400 TF = ((2451545.0 + 365.25) * 86400 - T0) T0 = 0 dT = .5 * 86400 time_series = np.arange(0, 365.25, 0.5) print("Starting Propagation") r_vec, v_vec = sf.orbit_prop_3body_RV(r_0, v_0, T0, TF, dT) print("Propagation Complete!") fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot3D(r_vec[:, 0], r_vec[:, 1], r_vec[:, 2]) elements = np.empty([np.shape(r_vec)[0], 6]) for i in range(np.shape(r_vec)[0]): elements[i, :] = sf.cart2elm(r_vec[i, :], v_vec[i, :], sf.earth.mu) print(np.shape(elements)) fig, ax = plt.subplots(3, sharex=True) elementals = ["a[km]", "e", "i[deg]", "RAAN[deg]", "Arg Periapsis [deg]"]
import space_functions as sf import numpy as np import matplotlib.pyplot as plt elements = [7000, 0, 75, 0, 0, 0] rho_0 = [2.5e-2, 0, 0] rho_dot_0 = [-1e-3, 0, 0] # part a print("5.1: ") r_t, v_t = sf.elm2cart(elements, sf.earth.mu) r_t_norm = np.linalg.norm(r_t) R = np.divide(r_t, r_t_norm) h = np.cross(r_t, v_t) W = np.divide(h, np.linalg.norm(h)) S = np.cross(W, R) Q_ijk = np.transpose(np.squeeze([R, S, W])) rho_ijk = np.matmul(Q_ijk, rho_0) rho_dot_ijk = np.matmul(Q_ijk, rho_dot_0) r_c = r_t + rho_ijk v_c = v_t + rho_dot_ijk print(r_c, v_c) # part b print("5.2: ") Ang_vel = h / r_t_norm**2 rho_dot_rel = np.multiply( 1000, np.matmul(np.transpose(Q_ijk), rho_dot_0 - np.cross(Ang_vel, rho_ijk)))
import space_functions as sf import matplotlib.pyplot as plt import numpy as np from colorama import Fore MU = 398600 a = 500000 e = 0.3 i = 50 RAAN = 350 arg_peri = 90 anomaly = 0 r_0, v_0 = sf.elm2cart([a, e, i, RAAN, arg_peri, anomaly], MU) T0 = 2451545.0 * 86400 tf = ((2451545.0 + 365.25) * 86400 - T0) T0 = 0 dt = .5 * 86400 time_series = np.arange(T0, tf, dt) - T0 r_vec, v_vec = sf.orbit_prop_3body(r_0, v_0, T0, tf, dt) elements = np.empty([np.shape(r_vec)[0], 6]) for i in range(np.shape(r_vec)[0]): elements[i, :] = sf.cart2elm(r_vec[i, :], v_vec[i, :], MU) print(np.shape(elements))
import numpy as np import numpy.linalg as lg import space_functions as sf MU = 398600.4415 RE = 6378.1363 JDos = 0.00108248 f = 3.353e-3 E_i = [8000, 0.1, 50, 45, 300, 0] E_f = [8500, 0.15294, 50, 45, 300, 0] r_i, v_i = sf.elm2cart(E_i, MU) r_f, v_f = sf.elm2cart(E_f, MU) delta_v = v_f-v_i print("∆v:") print(delta_v) v_r = np.dot(delta_v, r_i/lg.norm(r_i)) v_p = np.sqrt(lg.norm(delta_v)**2-v_r**2) print("|∆v_r|: "+str(v_r)+" km/s |∆v_⊥|: "+str(v_p)+" km/s")
MU = 398600.4415 J2 = 0.0010826267 J3 = -0.0000025327 class conditions: p_srp = 4.57e-6 * 1000**2 C_r = 1.5 A_m = 0.1 / 1000**2 C_D = 2 url = 'https://raw.githubusercontent.com/ggb367/Spring-2020/master/366L/hw7/density.csv' density_table = pd.read_csv(url) epoch = 2458200.5 # days r_0, v_0 = sf.elm2cart([6800, 0.005, 71, 300, 78, 0], MU) r_vec, v_vec = sf.orbit_prop_all_pert(r_0, v_0, 0, 86400, 30, conditions) r_bad, v_bad = sf.orbit_prop_rk(r_0, v_0, 0, 86400, 30) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot3D(r_vec[:, 0], r_vec[:, 1], r_vec[:, 2]) ax.plot3D(r_bad[:, 0], r_bad[:, 1], r_bad[:, 2]) print("With Perts:") print("The Final Position is: ", r_vec[-1, :], "The Final Velocity is: ", v_vec[-1, :]) print("Without Perts:") print("The Final Position is: ", r_bad[-1, :], "The Final Velocity is: ", v_bad[-1, :])
import math as m import matplotlib.pyplot as plt import numpy as np import numpy.linalg as lg import space_functions as sf MU = 398600.4415 # E - [a, e, i, RAAN, omega, nu] elements = [26000, 0.72, 75, 90, 270, 0] # time since periapsis passage is 0 for #1 so nu is 0 # #1 r_0, v_0 = sf.elm2cart(elements, MU) print("This is r:") print(r_0) print("This is v:") print(v_0) #2 time_series = np.arange(0, 86400 * 3, 20) nu_0 = 0 r_norm = lg.norm(r_0) h = np.cross(r_0, v_0) h_norm = lg.norm(h) eccent = np.cross(v_0, h) / MU - np.divide(r_0, r_norm) eccent_norm = lg.norm(eccent) a = (r_norm * (1 + eccent_norm * np.cos(nu_0))) / (1 - eccent_norm**2) # semimajor axis
import space_functions as sf import numpy as np import numpy.linalg as lg import matplotlib.pyplot as plt r_earth = [1, 0, 0] _, v_earth = sf.elm2cart([1, 0, 0, 0, 0, 0], 1) print(v_earth) t = [] C3 = [] u = np.arange(5, 170, 5) for step in u: r_mars, v_mars = sf.elm2cart([1.524, 0, 1.85, 0, 0, step], 1) mu_sun = 1 t_m = 1 a_min, e_min, t_abs, v_0 = sf.Lambert_MinEng(r_earth, r_mars) t.append(t_abs) v_inf = lg.norm(v_0-v_earth) C3.append(v_inf**2) plt.plot(u, t) plt.xlabel("u_mars, deg") plt.ylabel("Time [TU]") plt.title("Argument of Latitude of Mars vs. Absolute Minimum Time of Flight") plt.figure() plt.xlabel("u_mars, deg") plt.ylabel("C_3 [AU^2/TU^2]") plt.title("Argument of Latitude of Mars vs. Departure C_3") plt.plot(u, C3) # plt.yscale('log') plt.show()