pub struct Spring {
pub mass: f32,
pub stiffness: f32,
pub damping: f32,
}Expand description
A damped-harmonic-oscillator spring, solved in closed form.
Parameters follow the common “physical” convention: mass, stiffness (k)
and damping (c). The angular frequency is ω₀ = √(k/m) and the damping
ratio is ζ = c / (2√(k·m)).
Fields§
§mass: f32Oscillator mass (> 0).
stiffness: f32Spring stiffness k (> 0).
damping: f32Damping coefficient c (>= 0).
Implementations§
Source§impl Spring
impl Spring
Sourcepub fn new(mass: f32, stiffness: f32, damping: f32) -> Spring
pub fn new(mass: f32, stiffness: f32, damping: f32) -> Spring
Construct a spring from physical parameters.
Sourcepub fn from_frequency(omega0: f32, zeta: f32) -> Spring
pub fn from_frequency(omega0: f32, zeta: f32) -> Spring
Build a spring with the given natural frequency ω₀ (rad/s) and damping
ratio ζ (unit mass). ζ = 1 is critically damped.
Sourcepub fn natural_frequency(&self) -> f32
pub fn natural_frequency(&self) -> f32
The undamped natural angular frequency ω₀ = √(k/m).
Sourcepub fn damping_ratio(&self) -> f32
pub fn damping_ratio(&self) -> f32
The damping ratio ζ. < 1 under-, == 1 critically-, > 1 over-damped.
Sourcepub fn position(&self, from: f32, to: f32, v0: f32, t: f32) -> f32
pub fn position(&self, from: f32, to: f32, v0: f32, t: f32) -> f32
Position at time t (seconds) for a spring released from displacement
from - to with initial velocity v0, settling towards to.
Returns the absolute position (already offset by to). The solution is
the exact analytic response of m·x'' + c·x' + k·x = 0, so it is
numerically stable at any t and frame rate.
Trait Implementations§
impl Copy for Spring
impl StructuralPartialEq for Spring
Auto Trait Implementations§
impl Freeze for Spring
impl RefUnwindSafe for Spring
impl Send for Spring
impl Sync for Spring
impl Unpin for Spring
impl UnsafeUnpin for Spring
impl UnwindSafe for Spring
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more