Example #1
0
    def test_hyperbolic_orbits_2(self):
        # same orbit pulled from KSP at different times
        # lots of jitter, so tolerance for radius at time
        # is quite large (1%)
        o1 = Orbit(
            i  = 0.14149227768205455,
            Ω  = 3.977254620789031,
            ω  = 0.22395653996553322,
            e  = 1.0779572208620696,
            a  = -8855744.039847286,
            M0 = -6.0078569863130475,
            t0 = 34056398.642449796,
            body = CelestialBody(
                name = 'Kerbin',
                equatorial_radius = 600000.0,
                gravitational_parameter = 3531600035840.0,
                rotational_speed = 0.0002908894093707204,
            ),
        )
        o2 = Orbit(
            i  = 0.14311811324451928,
            Ω  = 3.9859850089566558,
            ω  = 0.21660875587091438,
            e  = 1.07736727693924,
            a  = -8880527.593801336,
            M0 = -0.012499818155590287,
            t0 = 34140525.998688884,
            body = CelestialBody(
                name = 'Kerbin',
                equatorial_radius = 600000.0,
                gravitational_parameter = 3531600035840.0,
                rotational_speed = 0.0002908894093707204,
            ),
        )

        tpe1 = o1.time_to_periapsis_at_epoch
        tpe2 = o2.time_to_periapsis_at_epoch
        self.isclose(o1.epoch+tpe1, o2.epoch+tpe2)

        χexpect1 = np.sqrt(-o1.a) \
            * (o1.eccentric_anomaly_at_time(o1.epoch+tpe1) \
            - o1.eccentric_anomaly_at_epoch)
        χexpect2 = np.sqrt(-o2.a) \
            * (o2.eccentric_anomaly_at_time(o2.epoch+tpe2) \
            - o2.eccentric_anomaly_at_epoch)

        tt = np.linspace(o1.epoch,o1.epoch+1*6*60*60,50)
        χχexpect = np.sqrt(-o1.a) \
            * (o1.eccentric_anomaly_at_time(tt) \
            - o1.eccentric_anomaly_at_epoch)
        χχ = o1.universal_anomaly_at_time(tt)

        t0 = o1.epoch
        r0 = o1.radius_at_epoch
        vr0 = o1.radial_speed_at_epoch
        a = o1.semi_major_axis
        x0 = o1.position_at_epoch/km
        v0 = o1.velocity_at_epoch
        #print('t0',t0)
        #print('r0',r0)
        #print('vr0',vr0)
        #print('a',a)
        #print('x0',x0)
        #print('v0',v0)

        #from matplotlib import pyplot
        #pyplot.plot(tt,χχexpect, color='blue')
        #pyplot.plot(tt[[0,-1]],χχexpect[[0,-1]], color='lightblue')
        #pyplot.plot(tt,χχ, color='red')
        #pyplot.plot(tt[[0,-1]],χχ[[0,-1]], color='pink')
        #pyplot.show()

        #print('θpe1',o1.true_anomaly_at_time(o1.epoch+tpe1))
        #print('θpe2',o2.true_anomaly_at_time(o2.epoch+tpe2))

        #print('rpeθ1',o1.radius_at_true_anomaly(
        #o1.true_anomaly_at_time(o1.epoch+tpe1)))
        #print('rpeθ2',o2.radius_at_true_anomaly(
        #o2.true_anomaly_at_time(o2.epoch+tpe2)))

        f1,g1,df1,dg1 = o1.lagrange_coefficients_at_time(o1.epoch+tpe1)
        f2,g2,df2,dg2 = o2.lagrange_coefficients_at_time(o2.epoch+tpe2)
        x1 = o1.position_at_lagrange_coefficients(f1,g1)
        x2 = o2.position_at_lagrange_coefficients(f2,g2)
        #print('rpe1(χexp)',np.sqrt(sum(x1**2)))
        #print('rpe2(χexp)',np.sqrt(sum(x2**2)))

        self.isclose(o2.periapsis, o2.radius_at_time(o2.epoch+tpe2))
        self.isclose(o1.periapsis, o1.radius_at_time(o1.epoch+tpe1))

        self.isclose(o1.periapsis, o2.periapsis,rtol=1e-2)
        self.isclose(o1.radius_at_time(o1.epoch+tpe1),
                     o2.radius_at_time(o2.epoch+tpe2),
                     rtol=0.01)