fn capture_moon(
    larger: &Planetesimal,
    smaller: &Planetesimal,
    stellar_mass: &f64,
    rng: &mut dyn RngCore,
) -> Planetesimal {
    let mut planet = larger.clone();
    let mut moon = smaller.clone();
    moon.is_moon = true;

    // Recalcualte planetary axis
    let new_mass = planet.mass + moon.mass;
    let new_axis = new_mass / (planet.mass / planet.a + moon.mass / moon.a);
    let term1 = planet.mass * (planet.a * (1.0 - planet.e.powf(2.0))).sqrt();
    let term2 = moon.mass * (moon.a * (1.0 - moon.e.powf(2.0))).sqrt();
    let term3 = (term1 + term2) / (new_mass * new_axis.sqrt());
    let term4 = 1.0 - term3.powf(2.0);
    let new_eccn = term4.abs().sqrt();
    planet.a = new_axis;
    planet.e = new_eccn;
    planet.distance_to_primary_star = new_axis;
    planet.hill_sphere = hill_sphere_au(&planet.a, &planet.e, &planet.mass, stellar_mass);

    // Add moon to planetary moons, recalculate disturbed orbits of moons
    planet.moons.append(&mut moon.moons);
    planet.moons.push(moon);

    for m in planet.moons.iter_mut() {
        m.a = rng.gen_range(0.0..planet.hill_sphere);
        m.e = random_eccentricity(rng);
        m.distance_to_primary_star = planet.a;
    }
    planet
}
/// Larger planetsimal capture smaller as moon
Larger planetsimal capture smaller as moon
Larger planetsimal capture smaller as moon
fn capture_moon(
    larger: &Planetesimal,
    smaller: &Planetesimal,
    stellar_mass: &f64,
    rng: &mut dyn RngCore,
) -> Planetesimal {
    let mut planet = larger.clone();
    let mut moon = smaller.clone();
    moon.is_moon = true;
    // Recalcualte planetary axis
    let new_mass = planet.mass + moon.mass;
    let new_axis = new_mass / (planet.mass / planet.a + moon.mass / moon.a);
    let term1 = planet.mass * (planet.a * (1.0 - planet.e.powf(2.0))).sqrt();
    let term2 = moon.mass * (moon.a * (1.0 - moon.e.powf(2.0))).sqrt();
    let term3 = (term1 + term2) / (new_mass * new_axis.sqrt());
    let term4 = 1.0 - term3.powf(2.0);
    let new_eccn = term4.abs().sqrt();
    planet.a = new_axis;
    planet.e = new_eccn;
    planet.distance_to_primary_star = new_axis;
    planet.hill_sphere = hill_sphere_au(&planet.a, &planet.e, &planet.mass, stellar_mass);
    // Add moon to planetary moons, recalculate disturbed orbits of moons
    planet.moons.append(&mut moon.moons);
    planet.moons.push(moon);
    for m in planet.moons.iter_mut() {
        m.a = rng.gen_range(0.0..planet.hill_sphere);
        m.e = random_eccentricity(rng);
        m.distance_to_primary_star = planet.a;
    }
    planet
}
fn capture_moon ( larger : & Planetesimal , smaller : & Planetesimal , stellar_mass : & f64 , rng : & mut dyn RngCore , ) -> Planetesimal { let mut planet = larger . clone ( ) ; let mut moon = smaller . clone ( ) ; moon . is_moon = true ; // Recalcualte planetary axis let new_mass = planet . mass + moon . mass ; let new_axis = new_mass / ( planet . mass / planet . a + moon . mass / moon . a ) ; let term1 = planet . mass * ( planet . a * ( 1.0 - planet . e . powf ( 2.0 ) ) ) . sqrt ( ) ; let term2 = moon . mass * ( moon . a * ( 1.0 - moon . e . powf ( 2.0 ) ) ) . sqrt ( ) ; let term3 = ( term1 + term2 ) / ( new_mass * new_axis . sqrt ( ) ) ; let term4 = 1.0 - term3 . powf ( 2.0 ) ; let new_eccn = term4 . abs ( ) . sqrt ( ) ; planet . a = new_axis ; planet . e = new_eccn ; planet . distance_to_primary_star = new_axis ; planet . hill_sphere = hill_sphere_au ( & planet . a , & planet . e , & planet . mass , stellar_mass ) ; // Add moon to planetary moons, recalculate disturbed orbits of moons planet . moons . append ( & mut moon . moons ) ; planet . moons . push ( moon ) ; for m in planet . moons . iter_mut ( ) { m . a = rng . gen_range ( 0.0 .. planet . hill_sphere ) ; m . e = random_eccentricity ( rng ) ; m . distance_to_primary_star = planet . a ; } planet }
Larger planetsimal capture smaller as moon
Larger planetsimal capture smaller as moon
larger
&Planetesimal
smaller
&Planetesimal
stellar_mass
&f64
rng
&mut dyn RngCore
larger
&Planetesimal
smaller
&Planetesimal
stellar_mass
&f64
rng
&mut dyn RngCore