The Brachistochrone is a classic problem about finding the path between two points where a ball will travel fastest (without friction). From greek: brachistos (shortest) and chronos (time).

The equations of motion are the same as those of RollerSingleSim. For derivation equations of motion see https://www.myphysicslab.com/RollerSimple.html and https://www.myphysicslab.com/RollerSpring.html.

Variables Array

The variables are stored in the VarsList as follows

vars[0] time
vars[1] position ball 0
vars[2] velocity ball 0
vars[3] x-position ball 0 (derived from vars[1] and path)
vars[4] y-position ball 0 (derived from vars[1] and path)
vars[5] position ball 1
vars[6] velocity ball 1
vars[7] x-position ball 1 (derived from vars[5] and path)
vars[8] y-position ball 1 (derived from vars[5] and path)
etc.

TO DO Graph is not very useful now. More useful would be to show each ball with a different color, and show y position vs. time. Perhaps name variables after the associated path. Or number the various paths and draw numbers on the balls.

TO DO Puzzle: if you turn off the repeat time and just let it run, the circle ball is ahead of the brachistochrone. Because it is a shorter path? But all the balls reach the same height at the same moment on the first repetition. After that they are no longer in sync. Why?

TO DO Don't put the x-position and y-position in the vars[] array; instead calculate these in getVariable(). See RollerFlightSim for an example.

TO DO could make an array of PathPoint, to avoid creating them so often.

Hierarchy (view full)

Implements

Constructors

Properties

choice_: number = -1

Which path was chosen by user, or -1 if no path chosen.

initialState_: null | number[] = null

Initial values.

simObjects_: SimObject[] = []

keep track of our SimObjects so that we can erase them

PATH_CHOSEN: "PATH_CHOSEN" = 'PATH_CHOSEN'

Event broadcast when a path is chosen.

Methods

  • Adds the given Observer to this Subject's list of Observers, so that the Observer will be notified of changes in this Subject. An Observer may call Subject.addObserver during its observe method.

    Parameters

    Returns void

  • Defines the differential equations of this ODESim; for an input set of variables, returns the current rate of change for each variable (the first derivative of each variable with respect to time).

    The timeStep is the time since the state variables were last fully calculated, which can be and often is zero. The current time can be regarded as getTime() + timeStep. The input variables correspond to the Simulation state at that time. Note that timeStep is different from the time step used to advance the Simulation (as in AdvanceStrategy.advance). The timeStep is typically used when finding collisions in CollisionSim.findCollisions.

    Parameters

    • vars: number[]

      the current array of state variables (input), corresponding to the state at getTime() + timeStep

    • change: number[]

      array of change rates for each variable (output), all values are zero on entry.

    • _timeStep: number

      the current time step (might be zero)

    Returns null | object

    null if the evaluation succeeds, otherwise an object relating to the error that occurred. The change array contains the output results.

  • Called at the end of a mouse drag operation, performs whatever action is appropriate. Only called if startDrag returned true.

    Parameters

    • _simObject: null | SimObject

      the SimObject being dragged, or null if no SimObject was found

    • _location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • _offset: Vector

      distance from the initial object position to the mouse location at start of drag.

    Returns void

  • Which path was chosen by user, or -1 if no path chosen.

    Returns number

    Which path was chosen by user, or -1 if no path chosen.

  • Called when a key is pressed or released, performs whatever action is appropriate for that event.

    Parameters

    • _evt: KeyboardEvent

      the KeyboardEvent that happened

    • _pressed: boolean

      true means this is a key-down event; false means a key-up event

    • _modifiers: ModifierKeys

      the modifier keys down during event

    Returns void

  • Called at each movement during a mouse drag, performs whatever action is appropriate. Only called if startDrag returned true. The SimObject being moved is passed in, along with the current mouse position, in simulation coordinates, and an offset calculated at the start of the drag.

    Setting the SimObject position to (x - offsetX, y - offsetY) will move the SimObject smoothly along with the mouse movement.

    Parameters

    • _simObject: null | SimObject

      the SimObject being dragged, or null if no SimObject was found

    • _location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • _offset: Vector

      distance from the initial object position (from DisplayObject.getPosition) to the mouse location at start of drag.

    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

  • Set which path the user has chosen for the 'fastest path'. Resets the variables to initial conditions. Creates a new set of SimObjects to represent the balls on the path. Creates the text message to display instructions to the user.

    Note: the simulation will still run without choosing a path; the path choice is only to allow decorating one of the paths with a different colored ball, and to present text instructions. *

    Parameters

    • choice: number

      Which path was chosen by user, or -1 if no path chosen.

    Returns void

  • Called at the start of a mouse drag. The nearest dragable SimObject is passed in, along with mouse position in simulation coordinates. If no dragable SimObject was found, null is passed for the first argument. If the EventHandler does not recognize the SimObject then it should return false.

    Parameters

    • _simObject: null | SimObject

      the SimObject that is nearest to the mouse drag coordinates, or null if no SimObject was found

    • location: Vector

      the location of the mouse in simulation coordinates of the SimView where simObject was found, or in the focus view if simObject is null.

    • _offset: Vector

      distance from the initial object position (from DisplayObject.getPosition) to the mouse location at start of drag

    • _dragBody: null | Vector

      location of 'drag point' on the SimObject in body coordinates of the SimObject; this is where for example a spring will be attached on the SimObject when dragging; or null when no SimObject was found

    • _modifiers: ModifierKeys

      the modifier keys down during event

    Returns boolean

    true if the EventHandler will handle dragging the SimObject

  • 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