예제 #1
0
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)))
rho_rel = np.multiply(1000, np.matmul(np.transpose(Q_ijk), rho_0))
print(rho_dot_rel)

# part c

T_t = sf.period(elements[0])
elements_chaser = sf.cart2elm(r_c, v_c, sf.earth.mu)
T_c = sf.period(elements_chaser[0])

r_c_vec, v_c_vec = sf.orbit_prop_rk(r_c, v_c, 0, T_c * 3, 20)
r_t_vec, v_t_vec = sf.orbit_prop_rk(r_t, v_t, 0, T_t * 3, 20)

rho_truth_ijk = r_c_vec - r_t_vec
# fig = plt.figure()
# ax = fig.add_subplot(111, projection='3d')
# ax.plot3D(r_c_vec[:, 0]-r_t_vec[:, 0], r_c_vec[:, 1]-r_t_vec[:, 1], r_c_vec[:, 2]-r_t_vec[:, 2])
# # ax.set_zlim(-2000, 2000)
# # ax.plot3D(r_t_vec[:, 0], r_t_vec[:, 1], r_t_vec[:, 2])
# # ax.plot3D(rho_truth[0, 0], rho_truth[0, 1], rho_truth[0, 2], 'g.')
# plt.figure()

rho_truth = np.empty(np.shape(rho_truth_ijk))
예제 #2
0
파일: 2.py 프로젝트: ggb367/Fall-2019
def main():
    def derivFcn(t, y):
        return two_body_orbit(t, y, MU)

    r_0 = np.array([-5282.628, -4217.988, 296.511])
    v_0 = np.array([-4.541972, 5.885228, 2.043106])
    E = sf.cart2elm(r_0, v_0, MU)
    a = E[0]
    P = 2 * m.pi * np.sqrt(a**3 / MU)
    T0 = 0.0
    times = np.arange(0, P * 3, 20)
    tF = P * 3
    dT = 20
    Y_0 = np.concatenate([r_0, v_0], axis=0)
    rv = ode(derivFcn)

    #  The integrator type 'dopri5' is the same as MATLAB's ode45()!
    #  rtol and atol are the relative and absolute tolerances, respectively
    rv.set_integrator('dopri5', rtol=1e-6, atol=1e-6)
    rv.set_initial_value(Y_0, T0)
    output = []
    output.append(np.insert(Y_0, 0, T0))

    # Run the integrator and populate output array with positions and velocities
    while rv.successful() and rv.t < tF:  # rv.successful() and
        rv.integrate(rv.t + dT)
        output.append(np.insert(rv.y, 0, rv.t))

    #  Convert the output a numpy array for later use
    output = np.array(output)
    r = np.sqrt(
        np.power(output[:, 1], 2) + np.power(output[:, 2], 2) +
        np.power(output[:, 3], 2))
    v = np.sqrt(
        np.power(output[:, 4], 2) + np.power(output[:, 5], 2) +
        np.power(output[:, 6], 2))
    a = np.empty(np.size(r))
    for i in range(np.size(r)):
        a[i] = np.divide(-MU, r[i]**2)
    t = output[:, 0]
    r_vec = np.empty([844, 3])
    v_vec = np.empty([844, 3])
    elms = np.empty([np.size(times) + 1, 6])
    for i in range(np.size(r)):
        r_vec[i, 0] = output[i, 1]
        r_vec[i, 1] = output[i, 2]
        r_vec[i, 2] = output[i, 3]
        v_vec[i, 0] = output[i, 4]
        v_vec[i, 1] = output[i, 5]
        v_vec[i, 2] = output[i, 6]
        elms[i] = sf.cart2elm(r_vec[i, :], v_vec[i, :], MU)
    eng = .5 * np.power(v, 2) - np.divide(
        MU, r) - (.5 * lg.norm(v_0)**2 - MU / lg.norm(r_0))

    plt.figure()
    plt.suptitle("Position, Velocity, & Acceleration vs. Time")
    plt.subplot(3, 1, 1)
    plt.plot(t / 3600, r)
    plt.ylabel('km', size=16)
    plt.subplot(3, 1, 2)
    plt.plot(t / 3600, v)
    plt.ylabel('km/s', size=16)
    plt.subplot(3, 1, 3)
    plt.plot(t / 3600, a)
    plt.ylabel('$km/s^2$', size=16)
    plt.xlabel("Hours", size=16)

    plt.figure()
    plt.title("Change in Energy vs. Time")
    plt.plot(t / 3600, eng)
    plt.ylabel('Energy', size=16)
    plt.xlabel('Hours', size=16)

    plt.figure()
    plt.suptitle("Orbital Elements vs. Time")
    plt.subplot(3, 2, 1)
    plt.plot(t / 3600, elms[:, 0])
    a = plt.ylabel('a [km]')
    plt.subplot(3, 2, 2)
    plt.plot(t / 3600, elms[:, 1])
    b = plt.ylabel('e')
    plt.subplot(3, 2, 3)
    plt.plot(t / 3600, elms[:, 2])
    c = plt.ylabel('i [deg]')
    plt.subplot(3, 2, 4)
    plt.plot(t / 3600, elms[:, 3])
    d = plt.ylabel('RAAN [deg]')
    plt.subplot(3, 2, 5)
    plt.plot(t / 3600, elms[:, 4])
    e = plt.ylabel('Arg of Periapsis [deg]')
    plt.subplot(3, 2, 6)
    plt.plot(t / 3600, elms[:, 5])
    plt.xlabel('Hours')
    f = plt.ylabel('Anomaly [deg]')
    plt.show()
    return
예제 #3
0
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]"]
try:
    for j in range(np.size(ax)):
        ax[j].plot(time_series, elements[:, j])
        ax[j].set_ylabel(elementals[j])
except Exception as e:
    print(Fore.RED + "There was a plotting error!")

plt.suptitle("Orbit Propagation with Solar Third Body Perturbations")
plt.xlabel("Time[Days]")

fig, ax = plt.subplots(2, sharex=True)
예제 #4
0
파일: 5.py 프로젝트: ggb367/Spring-2020
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))
fig, ax = plt.subplots(5, sharex=True)
elementals = ["a[km]", "e[deg]", "i[deg]", "RAAN[deg]", "Arg Periapsis [deg]"]
try:
    for j in range(np.size(ax)):
        ax[j].plot(np.divide(time_series, 86400), elements[:, j])
        ax[j].set_ylabel(elementals[j])
except Exception as e:
    print(Fore.RED + "There was a plotting error!")

plt.suptitle("Orbit Propagation with Solar Third Body Perturbations")
plt.xlabel("Time[Days]")

plt.figure()
예제 #5
0
파일: 3.py 프로젝트: ggb367/Fall-2019
    r_vec[i, 1] = output[i, 2]
    r_vec[i, 2] = output[i, 3]
    v_vec[i, 0] = output[i, 4]
    v_vec[i, 1] = output[i, 5]
    v_vec[i, 2] = output[i, 6]
    Y = [
        float(output[i, 1]),
        float(output[i, 2]),
        float(output[i, 3]),
        float(output[i, 4]),
        float(output[i, 5]),
        float(output[i, 6])
    ]
    dY = JTwo(t[i], Y, MU, jdos, RE)
    a[i] = -lg.norm([dY[3], dY[4], dY[5]])
    elms[i] = sf.cart2elm(r_vec[i, :], v_vec[i, :], MU)
    r_vec_norm = lg.norm(r_vec[i, :])
    U[i] = MU / r_vec_norm - (MU / r_vec_norm) * (jdos / 2) * (
        RE / r_vec_norm)**2 * (3 * (r_vec[i, 2] / r_vec_norm)**2 - 1)
    eng[i] = (np.dot(v_vec[i, :], v_vec[i, :]) / 2 - U[i]) - eng_0
E_0 = sf.cart2elm(r_0, v_0, MU, deg=False)
OMG_dot = (-(1.5 * (np.sqrt(MU) * jdos * RE**2) /
             (((1 - E_0[1]**2)**2) * E_0[0]**3.5))) * np.cos(E_0[2])
print("Omega dot: " + str(OMG_dot) + " rad/s")

plt.figure()
plt.suptitle("Position, Velocity, & Acceleration vs. Time")
plt.subplot(3, 1, 1)
plt.plot(t / 3600, r)
plt.ylabel('km', size=16)
plt.subplot(3, 1, 2)
예제 #6
0
import space_functions as sf
import numpy as np
import matplotlib.pyplot as plt

sun_pos = [149597870, 0, 0]  # km
elements = [10000, 0, 90, 0, 0, 0]
period = sf.period(elements[0])
# propogate orbit
r_0, v_0 = sf.elm2cart(elements, sf.earth.mu)
r_vec, v_vec = sf.orbit_prop_rk(r_0, v_0, 0, period, 3)
#get when it's in the shadow
shadow = np.array([sf.cylindrical_shadow(step, sun_pos) for step in r_vec])
plt.plot(shadow)

in_shadow = np.squeeze(np.where(shadow==0))
# print(in_shadow) #leaves shadow at step 1294, enters at step 2023

leave_shadow = sf.cart2elm(r_vec[2023, :], v_vec[2023, :], sf.earth.mu)
enter_shadow = sf.cart2elm(r_vec[1294, :], v_vec[1294, :], sf.earth.mu)

print("Enters Shadow at u=", enter_shadow[-1], "°")
print("Leaves Shadow at u=", leave_shadow[-1], "°")
plt.show()