Function get_velocities

Source
pub fn get_velocities(
    r1: [f64; 3],
    r2: [f64; 3],
    tof: f64,
    mu: f64,
    short: bool,
    eps: f64,
    max_iter: usize,
) -> Result<([f64; 3], [f64; 3]), LambertError>
Expand description

A lightweight function to solve Lambert’s problem, given two points in an orbit and the time of flight between them.

The first element of the return value is the velocity associated with the position r1 while the second is associated with r2. tof indicates the time of flight between the two points. mu indicates the gravitational parameter of the system: the product of Newton’s Gravitational constant and the mass of the central body. It is assumed that the mass of the orbiting object is negligible.

If the velocities are desired for trajectories that take the long path between r1 and r2, then short should be set to false.

If r1 or r2 are nearly colinear, then NaN results are possible. In this case, a small offset should be added to one or both of the vectors. If the root-finding method encounters NaN or fails to complete for another reason, then Err will be returned.

§Examples

The below line computes the time velocity required to leave Earth from the x axis and arrive at Mars on the -x axis (a Hohmann transfer) in meters per second after 8 months. We chose a time of flight (22372602 seconds) which will lead to velocities aligned with the y axis, but other times of flight may also be chosen.

get_velocities([1.496e11, 0.0, 0.0], [-2.28e11, 1.0e6, 0.0], 22372602, 1.327e20,
    true, 1e-7, 100);

A small offset was added to the positions to prevent them from being co-linear.

If the same function is run with short changed to false, the resulting velocities will have reversed y coordinate, except for small errors induced by the added offset.