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 exceeds a defined threshold.

This method triggers an AnimationController (a previously constructed _controller field) to simulate a fall of 300 pixels.
void _startFall() {
    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.

The end distance threshold (the constructor's third argument) must be specified as a positive number but can be reached in either the positive or negative direction. For example (assuming negative numbers represent higher physical positions than positive numbers, as is the case with the normal Canvas coordinate system), if the acceleration is positive ("down") the starting velocity is negative ("up"), and the starting distance is zero, the particle will climb from the origin, reach a plateau, then fall back towards and past the origin. If the end distance threshold is less than the height of the plateau, then the simulation will end during the climb; otherwise, it will end during the fall, after the particle travels below the origin by that distance.

See also:



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.


hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
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".
getter/setter pairinherited


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.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
toString() String
A string representation of this object.
x(double time) double
The position of the object in the simulation at the given time.


operator ==(Object other) bool
The equality operator.