pub struct SpringDescription {
pub mass: f64,
pub stiffness: f64,
pub damping: f64,
}Expand description
Structure that describes a spring’s constants.
Used to configure a SpringSimulation.
Fields§
§mass: f64The mass of the spring (m).
The units are arbitrary, but all springs within a system should use the same mass units.
The greater the mass, the larger the amplitude of oscillation, and the longer the time to return to the equilibrium position.
stiffness: f64The spring constant (k).
The units of stiffness are M/T², where M is the mass unit used for the
value of the mass property, and T is the
time unit used for driving the SpringSimulation.
Stiffness defines the spring constant, which measures the strength of the spring. A stiff spring applies more force to the object that is attached for some deviation from the rest position.
damping: f64The damping coefficient (c).
It is a pure number without physical meaning and describes the oscillation and decay of a system after being disturbed. The larger the damping, the fewer oscillations and smaller the amplitude of the elastic motion.
Do not confuse the damping coefficient (c) with the damping ratio
(ζ). To create a SpringDescription with a damping ratio, use
with_damping_ratio.
The units of the damping coefficient are M/T, where M is the mass unit
used for the value of the mass property,
and T is the time unit used for driving the SpringSimulation.
Implementations§
Source§impl SpringDescription
impl SpringDescription
Sourcepub fn with_damping_ratio(mass: f64, stiffness: f64) -> SpringDescription
pub fn with_damping_ratio(mass: f64, stiffness: f64) -> SpringDescription
Creates a spring given the mass (m), stiffness (k), and damping ratio (ζ). The damping ratio describes a gradual reduction in a spring oscillation. By using the damping ratio, you can define how rapidly the oscillations decay from one bounce to the next.
The damping ratio is especially useful when trying to determining the type of spring to create. A ratio of 1.0 creates a critically damped spring, > 1.0 creates an overdamped spring and < 1.0 an underdamped one.
See mass and
stiffness for the units for those
arguments. The damping ratio is unitless.
Sourcepub fn with_damping_ratio_value(
mass: f64,
stiffness: f64,
ratio: f64,
) -> SpringDescription
pub fn with_damping_ratio_value( mass: f64, stiffness: f64, ratio: f64, ) -> SpringDescription
Dart’s withDampingRatio ratio argument (default 1.0).
Sourcepub fn with_duration_and_bounce(
duration: Duration,
bounce: f64,
) -> SpringDescription
pub fn with_duration_and_bounce( duration: Duration, bounce: f64, ) -> SpringDescription
Creates a SpringDescription based on a desired animation duration
and bounce.
This provides an intuitive way to define a spring based on its visual
properties, duration and
bounce.
This constructor produces the same result as SwiftUI’s
spring(duration:bounce:blendDuration:) animation.
Sourcepub fn duration(&self) -> Duration
pub fn duration(&self) -> Duration
The duration parameter used in
with_duration_and_bounce.
This value defines the perceptual duration of the spring, controlling its overall pace. It is approximately equal to the time it takes for the spring to settle, but for highly bouncy springs, it instead corresponds to the oscillation period.
This duration does not represent the exact time for the spring to stop
moving. For example, when bounce is 1,
the spring oscillates indefinitely, even though duration has a finite
value. To determine when the motion has effectively stopped within a
certain tolerance, use SpringSimulation::is_done.
Defaults to 0.5 seconds.
Sourcepub fn bounce(&self) -> f64
pub fn bounce(&self) -> f64
The bounce parameter used in
with_duration_and_bounce.
This value controls how bouncy the spring is:
- A value of 0 results in a critically damped spring with no oscillation.
- Values between 0 and 1 produce underdamping, where the spring oscillates a few times before settling. A value of 1 represents an undamped spring that oscillates indefinitely.
- Negative values indicate overdamping, where the motion is slow and resistive, like moving through a thick fluid.
Defaults to 0.