def from_apses( body: Body, periapsis: Quantity, apoapsis: Quantity, sea_level: bool = False, ) -> Orbit: periapsis = body.adjust_height(periapsis, sea_level) apoapsis = body.adjust_height(apoapsis, sea_level) assert 0 * METERS <= periapsis <= apoapsis # E = -mu/2a = -mu/(A + P) energy = -body.mu / (periapsis + apoapsis) return Orbit(body, periapsis, energy)
def flyby( body: Body, periapsis: Quantity, scattering_angle: float, sea_level: bool = False, ) -> Orbit: periapsis = body.adjust_height(periapsis, sea_level) # alpha = 2 arccos(-1/e) - pi ==> cos((alpha + pi)/2) = -1/e # ==> e = -1/cos((alpha+pi)/2) = 1/cos((alpha-pi)/2) eccentricity = 1 / math.cos((scattering_angle - math.pi) / 2) # pe = a(1-e) = -mu/2E * (1-e) ==> E = (e-1) * mu / (2 * pe) energy = (eccentricity - 1) * body.mu / 2 / periapsis return Orbit(body, periapsis, energy)
def radial_trajectory(body: Body, max_height: Quantity, sea_level: bool = False) -> Orbit: max_height = body.adjust_height(max_height, sea_level) energy = -body.mu / max_height return Orbit(body, 0 * METERS, energy)