Orbit picker: calcuate accelleration on a per-body basis since I'm now planning to use the DSKD algorithm
[?]
Jun 16, 2021, 4:31 AM
DMOMPCJ2SNZ7SEAVPROANSOHQDGVL2OKD223EC24ZF5GJJ53SYTQCDependencies
- [2]
44YVVUNCOrbit picker: functions to calculate forces and Roche limits - [3]
PNOS6DEIOrbit picker: move vector stuff to its own module and add more impls
Change contents
- edit in orbitpick/src/vec3.rs at line 101
impl std::iter::Sum<V3> for V3 {fn sum<I: Iterator<Item = V3>>(iter: I) -> V3 {iter.fold(V3 {x: 0.,y: 0.,z: 0.,},|a, b| a + b,)}} - replacement in orbitpick/src/vec3.rs at line 116
(self.x * self.x + self.y * self.y + self.z * self.z).sqrt()self.squared_magnitude().sqrt()}pub fn squared_magnitude(self) -> f64 {self.x * self.x + self.y * self.y + self.z * self.z - edit in orbitpick/src/nbody.rs at line 21
}pub fn accelleration<N: Iterator<Item = Self>>(&self, others: N) -> V3 {others.filter(|other| other.position != self.position).map(|other| {let d = other.position - self.position;d.normalize() * other.mass / d.squared_magnitude()}).sum::<V3>()* G - edit in orbitpick/src/nbody.rs at line 47
}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