Post · 6 min read· pp. 62–65

Fly-by routines

The gravity assist technique, widely used in the Pioneer and Voyager missions, was developed by Michael Andrew Minovitch when he was a UCLA graduate student working as intern at NASA’s Jet Propulsion Laboratory. Many authors later refined the technique which, avoiding to solve directly the full three body problem, is based on patching the planetocentric hyperbola with incoming and outgoing (elliptic) trajectories. In pykep we offer the basic routines that allow to use this technique in the context of trajectory optimization and patched conics propagations.


Minovitch fly-by

pykep.fb_con(v_rel_in, v_rel_out, mu, safe_radius) : Alternative signature: fb_con(v_rel_in, v_rel_out, planet)

code
Computes the constraint violation during a fly-by modelled as an instantaneous rotation of the incoming and outgoing relative velocities (Mivovitch).
The two relative velocities must be identical in magnitude (equality constraint). The inequality constraint is defined in a differentiable
form as:

ineq=(1−2emin2)−cos⁡αineq = \left(1 - \frac{2}{e_{min}^2}\right) - \cos\alpha
where:
emin=1+V∞2Rsafeμe_{min} = 1 + V_{\infty}^2 \frac{R_{safe}}{\mu}
and:
cos⁡α=vrel,in⋅vrel,outVin2Vout2\cos\alpha = \frac{\mathbf v_{rel,in} \cdot \mathbf v_{rel,out}}{\sqrt{V_{in}^2 V_{out}^2}}
Note This function is often used in the multiple gravity assist low-thrust (MGA-LT) encoding of an interplanetary trajectory where multiple low-thrust legs are patched at the fly-by planets by forcing satisfaction for these constraints. Args: : *v\_rel\_in* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the incoming relative velocity. *v\_rel\_out* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the outgoing relative velocity. *mu* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planet gravitational parameter *safe\_radius* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planet safe radius *planet* ([`planet`](/u/b8b3c9975f4a752a#pykep-planet)): planet (in which case *mu* and *safe\_radius* will be extracted from this object). Note: this signature is slower and to be avoided. Returns: : [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) [[`float`](https://docs.python.org/3/builtins/functions.html#float), [`float`](https://docs.python.org/3/builtins/functions.html#float)]: The equality constraint violation (defined as the difference between the squared velocities) and the inequality constraint violation (negative if satisfied). Examples: : ```default

import pykep as pk eq, ineq = pk.fb_con(v_rel_in = [10.,1.,-4.], v_rel_out = [10.,1.,-4.], mu = 1., safe_radius = 1.)

code

    fb\_con(jacobian = False)

    Assembles and returns the `heyoka` symbolic expressions for the fly-by constraints.

    The symbolic variables are, in order: `[vx_i, vy_i, vz_i, vx_o, vy_o, vz_o]`.
    The symbolic parameters are `[par[0], par[1]] = [mu, safe_radius]`.

    The returned constraints are:

    
eq_V2=Vin2−Vout2eq\_V2 = V_{in}^2 - V_{out}^2
ineq_δ=(1−2emin2)−cos⁡αineq\_\delta = \left(1 - \frac{2}{e_{min}^2}\right) - \cos\alpha
where:
emin=1+safe_radiusμVin2e_{min} = 1 + \frac{safe\_radius}{\mu} V_{in}^2
and:
cos⁡α=vrel,in⋅vrel,outVin2Vout2\cos\alpha = \frac{\mathbf v_{rel,in} \cdot \mathbf v_{rel,out}}{\sqrt{V_{in}^2 V_{out}^2}}
Args: : *jacobian* ([`bool`](https://docs.python.org/3/builtins/functions.html#bool), optional): If `True`, also returns the Jacobian matrix of `[eq_V2, ineq_delta]` with respect to `[vx_i, vy_i, vz_i, vx_o, vy_o, vz_o]`. Returns: : [[`list`](https://docs.python.org/3/builtins/stdtypes.html#list), [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) or `None`]: : A pair `(expr, jac)` where: - *expr* is a list of two `heyoka.expression` objects representing `[eq_V2, ineq_delta]` - *jac* is either `None` (if `jacobian=False`) or a list of 12 `heyoka.expression` objects representing the 2x6 Jacobian Examples: : ```default >>> import pykep as pk >>> expr, jac = pk.fb_con() >>> len(expr), jac is None (2, True) >>> expr, jac = pk.fb_con(True) >>> len(expr), len(jac) (2, 12)

pykep.fb_dv(v_rel_in, v_rel_out, mu, safe_radius) : Alternative signature: fb_dv(v_rel_in, v_rel_out, planet)

code
Computes the ΔV\Delta V necessary to perform a fly-by modelled as an instantaneous rotation of the incoming and outgoing
relative velocities (Mivovitch). If planetary gravity is not enough to patch the incoming and outcoming conditions
(i.e. the [`fb_con()`](#pykep.fb_con) returns some constraint violation) a ΔV\Delta V is assumed
at the end of the planetocentric hyperbola.

Note

This function is often used in the multiple gravity assist (MGA) encoding of an interplanetary trajectory where multiple
Lambert arcs are patched at the fly-by planets by applying a hopefully vanishing ΔV\Delta V.

Args:
:   *v\_rel\_in* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the incoming relative velocity.

    *v\_rel\_out* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the outgoing relative velocity.

    *mu* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planet gravitational parameter

    *safe\_radius* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planet safe radius

    *planet* ([`planet`](/u/b8b3c9975f4a752a#pykep-planet)): planet (in which case *mu* and *safe\_radius* will be extracted from this object). Note: this signature is slower and to be avoided.

Returns:
:   [`float`](https://docs.python.org/3/builtins/functions.html#float): The magnitude of the required ΔV\Delta V

Examples:
:   ```default

import pykep as pk DV = pk.fb_dv(v_rel_in = [10.,1.,-4.], v_rel_out = [10.,1.,-4.], mu = 1., safe_radius = 1.)

code

pykep.fb\_vout(*v\_in*, *v\_pla*, *rp*, *beta*, *mu*)
:   Propagates incoming conditions through a planetary encounter (fly-by) assuming an instantaneous rotation of magnitude δ\delta of
    the incoming and outgoing relative velocities (Mivovitch). The planetocentric hyperbola (hence the angle δ\delta) is fully
    determined by the incoming condition v∞=vin−vplav_{\infty} = \mathbf v_{in} - \mathbf v_{pla} as well as by its pericenter rpr_p
    and an angle β\beta defining the orientation of the orbital plane. Eventually the outgoing conditions are computed as:

    
vout=vin+v∞out\mathbf v_{out} = \mathbf v_{in} + \mathbf v_{\infty}^{out}
v∞out=∣v∞in∣(cos⁡δb^1+sin⁡δcos⁡βb^2+sin⁡δsin⁡βb^3)\mathbf v_{\infty}^{out} = |\mathbf v_{\infty}^{in}| \left( \cos\delta\hat{\mathbf b}_1 +\sin\delta\cos\beta\hat{\mathbf b}_2 +\sin\delta\sin\beta\hat{\mathbf b}_3 \right)
where the [b^1,b^2,b^3][\hat{\mathbf b}_1, \hat{\mathbf b}_2, \hat{\mathbf b}_3] frame is defined by the incoming relative velocity (normalized), b^1×vpla\hat{\mathbf b}_1 \times \mathbf v_{pla} (normalized) and completing the right handed frame. Note This function is often used in the multiple gravity assist with DSM (MGA-DSM) encoding of an interplanetary trajectory where multiple impulsive manoeuvres are allowed between planetary fly-bys. Args: : *v\_in* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the incoming velocity (note: this is NOT the relative velocity, rather the absolute and in the same frame as *v\_pla*). *v\_pla* ([`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,)): Cartesian components of the planet velocity. *rp* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planetocentric hyperbola pericenter radius. *beta* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planetocentric hyperbola plane angle. *mu* ([`float`](https://docs.python.org/3/builtins/functions.html#float)): planet gravitational parameter. Returns: : [`list`](https://docs.python.org/3/builtins/stdtypes.html#list) (3,): The outgoing velocity in the frame of *v\_pla* (inertial). Examples: : ```default >>> import pykep as pk >>> DV = pk.fb_vout(v_in = [1.,1.,1], v_pla = [10.,1.,-4.], rp = 1., mu = 1., beta=1.2)