Particle

Struct Particle 

Source
pub struct Particle { /* private fields */ }
Expand description

A struct representing a particle record in the simulation.

Implementations§

Source§

impl Particle

Source

pub fn from_data(position: Vec3, velocity: Vec3, mass: f64) -> Self

Particle constructor from position, initial velocity and mass.

Source

pub fn get_force(&self) -> Vec3

Returns the current force of the particle.

Source

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.

Source

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.

Source

pub fn get_position(&self) -> Vec3

Returns the current position of the particle.

Source

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.

Source

pub fn get_velocity(&self) -> Vec3

Returns the current velocity of the particle.

Source

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.

Source

pub fn get_mass(&self) -> f64

Returns the constant mass of the particle.

Source

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).
Source

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.
Source

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).
Source

pub fn mass_product(particle1: &Particle, particle2: &Particle) -> f64

Calculate the product of the masses of two particles.

Trait Implementations§

Source§

impl Debug for Particle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Particle

Source§

fn default() -> Particle

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Particle

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Particle

Source§

fn eq(&self, other: &Particle) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Particle

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Particle

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,