GravitySimulation class

A simulation that applies a constant accelerating force.

Models a particle that follows Newton's second law of motion. The simulation ends when the position reaches a defined point.

Sample code

This method triggers an AnimationController (a previously constructed _controller field) to simulate a fall of 300 pixels.

void _startFall() {
  _controller.animateWith(GravitySimulation(
    10.0, // acceleration, pixels per second per second
    0.0, // starting position, pixels
    300.0, // ending position, pixels
    0.0, // starting velocity, pixels per second
  ));
}

This AnimationController could be used with an AnimatedBuilder to animate the position of a child as if it was falling.

See also:

Inheritance

Constructors

GravitySimulation(double acceleration, double distance, double endDistance, double velocity)
Creates a GravitySimulation using the given arguments, which are, respectively: an acceleration that is to be applied continually over time; an initial position relative to an origin; the magnitude of the distance from that origin beyond which (in either direction) to consider the simulation to be "done", which must be positive; and an initial velocity. [...]

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited
tolerance Tolerance
How close to the actual end of the simulation a value at a particular time must be before isDone considers the simulation to be "done". [...]
read / write, inherited

Methods

dx(double time) → double
The velocity of the object in the simulation at the given time.
isDone(double time) → bool
Whether the simulation is "done" at the given time.
x(double time) → double
The position of the object in the simulation at the given time.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited