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.
link
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.

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:

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.
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

Methods

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

Operators

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