pub struct Particle { /* private fields */ }Expand description
A struct representing a particle record in the simulation.
Implementations§
Source§impl Particle
impl Particle
Sourcepub fn from_data(position: Vec3, velocity: Vec3, mass: f64) -> Self
pub fn from_data(position: Vec3, velocity: Vec3, mass: f64) -> Self
Particle constructor from position, initial velocity and mass.
Sourcepub fn delay_force(&mut self)
pub fn delay_force(&mut self)
Propagates the current force to the old force. This has to be called every time step before invoking Particle::apply_force to apply new forces.
Sourcepub fn apply_force(&mut self, force: Vec3)
pub fn apply_force(&mut self, force: Vec3)
Applies the given force to the particle (addition). It assumes that the force was reset with Particle::delay_force in a timestep.
Sourcepub fn get_position(&self) -> Vec3
pub fn get_position(&self) -> Vec3
Returns the current position of the particle.
Sourcepub fn update_position(&mut self, delta_time: f64)
pub fn update_position(&mut self, delta_time: f64)
Calculate the updated position of the particle given a delta time step. This functionality is constant across different simulation algorithms, so it is implemented here.
Sourcepub fn get_velocity(&self) -> Vec3
pub fn get_velocity(&self) -> Vec3
Returns the current velocity of the particle.
Sourcepub fn update_velocity(&mut self, delta_time: f64)
pub fn update_velocity(&mut self, delta_time: f64)
Calculate the updated velocity of the particle given a delta time step. This functionality is constant across different simulation algorithms, so it is implemented here.
Sourcepub fn position_difference(particle1: &Particle, particle2: &Particle) -> Vec3
pub fn position_difference(particle1: &Particle, particle2: &Particle) -> Vec3
Calculate the vector difference between two particles’ positions. Note that the order of the particles affects the sign.
direction(a, b) == -direction(b, a).
Sourcepub fn direction(particle1: &Particle, particle2: &Particle) -> Option<Vec3>
pub fn direction(particle1: &Particle, particle2: &Particle) -> Option<Vec3>
Calculate the normalized vector difference between two particles’ positions. Note that the order of the particles affects the sign.
- If result is
Some:direction(a, b) == -direction(b, a). - If result is
None:direction(a, b) == direction(b, a) == None.
Sourcepub fn distance(particle1: &Particle, particle2: &Particle) -> f64
pub fn distance(particle1: &Particle, particle2: &Particle) -> f64
Calculate the distance between two particles’ positions. This function is symmetric:
distance(a, b) == distance(b, a).
Sourcepub fn mass_product(particle1: &Particle, particle2: &Particle) -> f64
pub fn mass_product(particle1: &Particle, particle2: &Particle) -> f64
Calculate the product of the masses of two particles.