Simulation of a double pendulum hanging from a moveable anchor point.

The anchor point or 'cart' position can be given any program of motion, it is not affected by the pendulum movement at all. So you could regard the cart as a having infinite mass in comparison to the pendulums. Or that some outside entity is applying whatever forces are needed on the cart to keep it to the fixed program of motion.

The cart is both dragable by the mouse and/or can have a periodic up/down motion. With the periodic motion, this becomes a demonstration of an 'inverted pendulum': if the periodic motion is rapid enough, the pendulum position pointing straight up becomes stable.

There is a parallel but independent simulation for the movement of the cart. The cart is regarded as a point mass that is dragable by a spring force controlled by the user's mouse. Optionally, the periodic force moves the cart up and down.

Note that when changing the anchor amplitude or frequency, that we set the anchor vertical velocity such that the anchor stays centered at its current position. Otherwise, the anchor tends to move rapidly out of view.

Derivation of equations of motion is shown at https://www.myphysicslab.com/Moveable-pendulum.html.

Variables Array

The variables are stored in the VarsList as follows

vars[0] = theta_1   angle of rod 1
vars[1] = omega_1 = theta_1'  angular velocity of rod 1
vars[2] = theta_2   angle of rod 2
vars[3] = omega_2 = theta_2'  angular velocity of rod 2
vars[4] = t  time
vars[5] = x_0  anchor X position
vars[6] = vx_0 = x_0'  anchor X velocity
vars[7] = y_0  anchor Y position
vars[8] = vy_0 = y_0'  anchor Y velocity

To Do

Make a Parameter for whether to limit angles to +/- Pi. For some graphs you want this, but for other graphs you don't want it.

The energy values are not correct. When the anchor is moving then energy is being added to the pendulum. The potential energy should change from moving up and down in gravitational field. The kinetic energy should include the motion added by the anchor.

TO DO add ParameterBoolean specifying whether to limit angles to +/-Pi.

Hierarchy (view full)

Implements

Constructors

Properties

amplitude_: number = 200

amplitude of driving force on anchor to make periodic up/down motion

anchorDamping_: number = 0.8

damping applied to anchor

damping_: number = 0.5

damping of pendulum

frequency_: number = 30

frequency of driving force on anchor to make periodic up/down motion

initialState_: null | number[] = null

Initial values.

length1_: number = 1

length of pendulum rod 1

length2_: number = 1

length of pendulum rod 2

mouse_: PointMass = ...

Follows the mouse position while applying spring force to anchor

pendulumDragging_: boolean = false

true when dragging pendulum bob

potentialOffset_: number = 0

potential energy offset

running_: boolean = false

Whether the simulation is running; determines whether mouse dragging of anchor results in applying spring force or just moving the anchor directly.

springDragging_: boolean = false

true when applying spring force to anchor by mouse drag

springStiffness_: number = 3

stiffness of spring made for dragging anchor

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

  • 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

  • Calculates anchor Y velocity, so that the anchor stays visible, as though in a 'steady state'. Otherwise the anchor tends to quickly wander off screen.

    Derivation:

    y'' = a sin(frequency t)
    y' = integral(y'' dt) = -(a/frequency) cos(frequency t) + C
    y = integral(y' dt) = -(a/frequency^2) sin(frequency t) + C t + C_2
    

    To avoid the anchor wandering need C = 0 therefore

    at time t = 0, this gives y' = -(a/frequency)
    

    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 amplitude of of driving force on anchor to make periodic up/down motion

    Parameters

    • value: number

      amplitude of driving force on anchor

    Returns void

  • Informs the simulation of whether the clock is running, which determines whether mouse dragging of anchor results in applying spring force or just moving the anchor directly.

    Parameters

    • value: boolean

    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