SpringSim class
A physically accurate mass-spring-damper simulation.
Produces three distinct behaviors based on the damping ratio ζ:
- Under-damped (ζ < 1): oscillates before settling (wobbly/spring)
- Critically damped (ζ = 1): fastest settle without oscillation
- Over-damped (ζ > 1): slow, exponential approach to target
Usage:
final sim = SpringSim(from: 0.0, to: 1.0, stiffness: 180, damping: 12);
final pos = sim.position(0.5); // position at t=0.5 seconds
- Inheritance
-
- Object
- PhysicsSimulator
- SpringSim
Constructors
Properties
- damping → double
-
Damping coefficient. Higher = less oscillation.
final
- dampingRatio → double
-
Damping ratio ζ (zeta). < 1 = under, = 1 = critical, > 1 = over.
no setter
- from → double
-
Starting position.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → String
-
Unique identifier for this simulator type.
no setteroverride
- initialVelocity → double
-
Initial velocity (units/sec). Positive = moving toward target.
final
- mass → double
-
Object mass (kg). Higher = slower response.
final
- naturalFrequency → double
-
Natural angular frequency ω₀.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- stiffness → double
-
Spring stiffness (N/m). Higher = faster snapping.
final
- to → double
-
Target (rest) position.
final
Methods
-
isDone(
double t) → bool -
True when the simulation has effectively come to rest.
override
-
normalized(
double t, {required double from, required double to}) → double -
Normalizes position to
0.0, 1.0based onfromandto. Useful for driving AnimationController.value.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
position(
double t) → double -
Position at time
t(seconds).override -
sample(
{double durationSec = 2.0, int sampleHz = 60}) → List< double> -
Samples the simulation at
sampleHzfordurationSecseconds.inherited -
settleDuration(
{double maxTime = 10.0, int resolution = 120}) → double -
Returns the time (seconds) at which isDone first becomes true,
sampled at
resolutionsteps per second. ReturnsmaxTimeif never done.inherited -
toString(
) → String -
A string representation of this object.
override
-
velocity(
double t) → double -
Velocity at time
t(units/second).override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
gentle(
{double from = 0.0, double to = 1.0}) → SpringSim - Gentle, smooth approach — overlays, dialogs.
-
ios(
{double from = 0.0, double to = 1.0}) → SpringSim - iOS-style interactive spring — tight and responsive.
-
material(
{double from = 0.0, double to = 1.0}) → SpringSim - Material You emphasized spring.
-
wobbly(
{double from = 0.0, double to = 1.0}) → SpringSim - Wobbly — good for list item reveals.