Orbit picker: functions to calculate forces and Roche limits

[?]
Jun 16, 2021, 3:21 AM
44YVVUNCI6DMMP6SF7LCBGWDYFAENLRKZ5TUMRSB62YOCL5QXBLAC

Dependencies

  • [2] PNOS6DEI Orbit picker: move vector stuff to its own module and add more impls
  • [3] EWUP525B Basic vector arithmetic for the orbit picker
  • [4] K3V2JNKC Initialize sub-project for choosing lunar orbital parameters
  • [5] 4LTVYHHI Add async runtime for the orbital parameter picker

Change contents

  • replacement in orbitpick/src/vec3.rs at line 1
    [2.10][2.11:39]()
    #[derive(Copy,Clone,Debug)]
    [2.10]
    [2.39]
    #[derive(Copy, Clone, Debug, PartialEq)]
  • replacement in orbitpick/src/vec3.rs at line 5
    [2.87][2.87:102]()
    pub z: f64
    [2.87]
    [2.102]
    pub z: f64,
  • replacement in orbitpick/src/vec3.rs at line 103
    [2.2030][2.2030:2093]()
    (self.x*self.x + self.y*self.y + self.z*self.z).sqrt()
    [2.2030]
    [2.2093]
    (self.x * self.x + self.y * self.y + self.z * self.z).sqrt()
  • file addition: nbody.rs (----------)
    [3.19]
    use crate::vec3::V3;
    use std::f64::consts::PI;
    pub const G: f64 = 6.67430e-11;
    #[derive(Debug, Clone, Copy)]
    pub struct Body {
    pub mass: f64,
    pub position: V3,
    pub velocity: V3,
    pub radius: f64,
    }
    impl Body {
    pub fn momentum(&self) -> V3 {
    self.velocity * self.mass
    }
    pub fn density(&self) -> f64 {
    self.mass / (4. / 3. * PI * self.radius * self.radius * self.radius)
    }
    pub fn roche_limit(&self, other: &Self, variant: RocheLimitType) -> f64 {
    self.radius
    * (2. * self.density() / other.density()).powf(1. / 3.)
    * match variant {
    RocheLimitType::Rigid => 1.,
    RocheLimitType::Fluid => 2.44,
    }
    }
    }
    pub enum RocheLimitType {
    Rigid,
    Fluid,
    }
    pub fn forces(state: Vec<Body>) -> Vec<V3> {
    let mut result = vec![
    V3 {
    x: 0.,
    y: 0.,
    z: 0.
    };
    state.len()
    ];
    for (ix, xb) in state.iter().enumerate() {
    for (iy, yb) in state.iter().enumerate() {
    if ix != iy {
    let d = yb.position - xb.position;
    let r2 = d.x * d.x + d.y * d.y + d.z * d.z;
    let f = xb.mass * yb.mass / r2;
    result[ix] += d.normalize() * f;
    }
    }
    }
    for b in result.iter_mut() {
    *b *= G;
    }
    result
    }
  • edit in orbitpick/src/main.rs at line 3
    [3.466]
    [2.2414]
    mod nbody;
  • replacement in orbitpick/src/main.rs at line 9
    [3.45][3.43:74](),[3.43][3.43:74]()
    println!("Hello, world!");
    [3.45]
    [3.74]
    println!("{}", nbody::G);