def test_flyby_curtis(theta, expected_V_2_v): # Data from Curtis, Example 8.6 periapsis_h = 300 * u.km V_1_v = [37.51, 2.782, 0] * u.km / u.s # In some reference frame V = [35.02, 0, 0] * u.km / u.s expected_delta = 103.6 * u.deg V_2_v, delta = compute_flyby(V_1_v, V, Venus.k, Venus.R + periapsis_h, theta) assert_quantity_allclose(V_2_v, expected_V_2_v, rtol=1e-3, atol=1e-15 * u.km / u.s) assert_quantity_allclose(delta, expected_delta, rtol=1e-3)
def func(theta): V_2_v, _ = compute_flyby(v1_pre, V, Venus.k, d_flyby_1, theta * u.rad) ss_1 = Orbit.from_vectors(Sun, r1, V_2_v, epoch=flyby_1_time) return (ss_1.period - T_ref).to(u.day).value
# In[22]: V.to(u.km / u.day) # In[23]: h = 2548 * u.km # In[24]: d_flyby_1 = Venus.R + h d_flyby_1.to(u.km) # In[25]: V_2_v_, delta_ = compute_flyby(v1_pre, V, Venus.k, d_flyby_1) # In[26]: norm(V_2_v_) # ## 4. Optimization # # Now we will try to find the value of $\theta$ that satisfies our requirements. # In[27]: from poliastro.twobody import Orbit # In[28]:
T_ref = 150 * u.day k = Sun.k a_ref = np.cbrt(k * T_ref**2 / (4 * np.pi**2)).to(u.km) energy_ref = (-k / (2 * a_ref)).to(u.J / u.kg) flyby_1_time = Time("2018-09-28", scale="tdb") r_mag_ref = norm(Orbit.from_body_ephem(Venus, epoch=flyby_1_time).r) v_mag_ref = np.sqrt(2 * k / r_mag_ref - k / a_ref) d_launch = Time("2018-08-11", scale="tdb") ss0 = Orbit.from_body_ephem(Earth, d_launch) ss1 = Orbit.from_body_ephem(Venus, epoch=flyby_1_time) tof = flyby_1_time - d_launch (v0, v1_pre), = iod.lambert(Sun.k, ss0.r, ss1.r, tof.to(u.s)) V = Orbit.from_body_ephem(Venus, epoch=flyby_1_time).v h = 2548 * u.km d_flyby_1 = Venus.R + h V_2_v_, delta_ = compute_flyby(v1_pre, V, Venus.k, d_flyby_1) theta_range = np.linspace(0, 2 * np.pi) def func(theta): V_2_v, _ = compute_flyby(v1_pre, V, Venus.k, d_flyby_1, theta * u.rad) ss_1 = Orbit.from_vectors(Sun, ss1.r, V_2_v, epoch=flyby_1_time) return (ss_1.period - T_ref).to(u.day).value plt.plot(theta_range, [func(theta) for theta in theta_range]) plt.axhline(0, color="k", linestyle="dashed") theta_opt_a = brentq(func, 0, 1) * u.rad print(theta_opt_a.to(u.deg)) theta_opt_b = brentq(func, 4, 5) * u.rad print(theta_opt_b.to(u.deg))