Added 3D possibility to body
This commit is contained in:
parent
966aabc649
commit
adf53b7703
@ -9,14 +9,14 @@ pub async fn run() {
|
||||
let mut sim = simulator.write().unwrap();
|
||||
sim.add_body(Body {
|
||||
name: "Sun".into(),
|
||||
position: [0.0, 0.0],
|
||||
velocity: [0.0, 0.0],
|
||||
position: Vector3::new(0.0, 0.0, 0.0),
|
||||
velocity: Vector3::new(0.0, 0.0, 0.0),
|
||||
mass: 1.989e30,
|
||||
});
|
||||
sim.add_body(Body {
|
||||
name: "Earth".into(),
|
||||
position: [1.496e11, 0.0],
|
||||
velocity: [0.0, 29780.0],
|
||||
position: Vector3::new(1.496e11, 0.0, 0.0),
|
||||
velocity: Vector3::new(0.0, 29780.0, 0.0),
|
||||
mass: 5.972e24,
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,13 +1,15 @@
|
||||
use cgmath::Vector3;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Body {
|
||||
pub name: String,
|
||||
pub mass: f64,
|
||||
pub position: [f64; 2],
|
||||
pub velocity: [f64; 2],
|
||||
pub position: Vector3<f64>,
|
||||
pub velocity: Vector3<f64>,
|
||||
}
|
||||
|
||||
impl Body {
|
||||
pub fn new(name: &str, mass: f64, position: [f64; 2], velocity: [f64; 2]) -> Self {
|
||||
pub fn new(name: &str, mass: f64, position: Vector3<f64>, velocity: Vector3<f64>) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
mass,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::sync::Mutex;
|
||||
use cgmath::Vector3;
|
||||
use crate::body::Body;
|
||||
use rayon::prelude::*;
|
||||
|
||||
@ -36,8 +37,8 @@ impl Simulator {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct State {
|
||||
position: [f64; 2],
|
||||
velocity: [f64; 2],
|
||||
position: Vector3<f64>,
|
||||
velocity: Vector3<f64>,
|
||||
}
|
||||
|
||||
let original_states: Vec<State> = self
|
||||
@ -96,14 +97,12 @@ impl Simulator {
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, s)| State {
|
||||
position: [
|
||||
s.position[0] + k1_pos[i][0] * dt / 2.0,
|
||||
s.position[1] + k1_pos[i][1] * dt / 2.0,
|
||||
],
|
||||
velocity: [
|
||||
position: Vector3::new(s.position[0], s.position[1], 0.0),
|
||||
velocity: Vector3::new(
|
||||
s.velocity[0] + k1_vel[i][0] * dt / 2.0,
|
||||
s.velocity[1] + k1_vel[i][1] * dt / 2.0,
|
||||
],
|
||||
0.0,
|
||||
),
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user