Applies constant downward gravitational force to a set of MassObjects.

The set of objects can be specified with the addBody method, or the GravityLaw can observe a SimList and automatically add all bodies that have mass to the set of objects.

Zero Energy Level

GravityLaw has a default zero potential energy level which is used for MassObjects that return null from getZeroEnergyLevel. This allows adding objects to a simulation without needing to set the zero energy level on each object. You can override this default zero energy level for an object with MassObject.setZeroEnergyLevel.

Parameters Created

Hierarchy (view full)

Implements

Constructors

Methods

  • Adds any MassObjects with finite mass among the given list of SimObjects.

    Parameters

    • bodies: SimObject[]

      set of SimObjects to possibly add

    Returns void

  • Adds the SimObject to list of objects that GravityLaw applies forces to, but only if it has positive finite mass

    Parameters

    Returns void

  • Connect to the given SimList, so that the force applies to all objects in the SimList. Also adds all existing bodies on that SimList. *

    Parameters

    • simList: SimList

      the SimList to connect with

    Returns void

  • Ensures this ForceLaw is not connected to anything and so can be garbage collected. For example, if this ForceLaw is an Observer, this will stop observing its Subject.

    Returns void

  • Returns the magnitude of the gravity force.

    Returns number

    the magnitude of the gravity force

  • Returns the vertical world coordinate where a body has zero potential energy. Can override for a particular body with MassObject.setZeroEnergyLevel.

    Returns number

    the vertical world coordinate where a body has zero potential energy

  • Notifies this Observer that a change has occurred in the Subject.

    Parameters

    • event: SubjectEvent

      contains information about what has changed in the Subject: typically either a one-time GenericEvent, or a change to the value of a Parameter

    Returns void

  • Sets whether this Subject will broadcast events, typically used to temporarily disable broadcasting. Intended to be used in situations where a subclass overrides a method that broadcasts an event. This allows the subclass to prevent the superclass broadcasting that event, so that the subclass can broadcast the event when the method is completed.

    Parameters

    • value: boolean

      whether this Subject should broadcast events

    Returns boolean

    the previous value

  • Sets the magnitude of the gravity force.

    Parameters

    • gravity: number

      the magnitude of the gravity force

    Returns void

  • Sets the vertical world coordinate where a body has zero potential energy. Can override for a particular body with MassObject.setZeroEnergyLevel.

    Parameters

    • value: number

      the vertical world coordinate where a body has zero potential energy

    Returns void

  • Returns a minimal string representation of this object, usually giving just identity information like the class name and name of the object.

    For an object whose main purpose is to represent another Printable object, it is recommended to include the result of calling toStringShort on that other object. For example, calling toStringShort() on a DisplayShape might return something like this:

    DisplayShape{polygon:Polygon{'chain3'}}
    

    Returns string

    a minimal string representation of this object.

Generated using TypeDoc