Skip to main content

escape_velocity

Function escape_velocity 

Source
pub fn escape_velocity(source_mass: f64, distance: f64) -> Option<f64>
Expand description

Computes the escape velocity from a source mass at a distance.

Formula: v = sqrt(2 * G * M / r)

Returns None when source_mass is negative, when distance is less than or equal to zero, or when the computed result is not finite.

ยงExamples

use use_gravity::escape_velocity;

let velocity = escape_velocity(5.972e24, 6.371e6).unwrap();

assert!((velocity - 11_186.0).abs() < 2.0);