Demonstration applet - `Y hang'

This Java applet demonstrates several ideas that may be applied to interactive simulations. The applet models a rope supporting a weight with the load shared between two anchors (what European cavers call a `Y hang'). The user may interact with the model by moving either the knot or the anchors in the display area, or by pressing one of the buttons or entering text in the control area. If the knot is positioned above the anchors then the model starts a thread which simulates (without realism!) the knot falling.

Instructions

The anchors are shown as blue circles and the knot is just where the three lines meet (two `ropes' from the anchors and the rope supporting the weight).

The anchors and knot can be picked up and dragged around by clicking on the blue circles or within a similar radius of the knot. As these points are moved the angle readout is updated. The readout gives the angle between the two anchor ropes. An attempt to drag either the knot or an anchor outside the display area results in it being dropped at the edge.

If the positions of the knot and anchors are unstable (for example, the knot above the anchors) then the knot will `fall' within the constraints of the rope lengths when placed.

The knot may be moved vertically to give particular angles by clicking on one of the Preset buttons or by entering an angle in the Angle text box. Entries are clipped to the range 1 to 180 degrees.

The weight supported by the rope arrangement can be set using the Weight text box and will be displayed at the foot of the display area unless the knot is out of view (off the bottom). The forces on the two anchors are displayed by the anchors. Slack or falling ropes are indicated by `?', very high forces are indicated by `!!!'.

Inside the applet

The applet uses four classes: YHang, Simulation, DiagramPanel, and ControlPanel. YHang inherits from Applet and is thus the `main' for this applet.

The YHang class creates instances of the three other classes and sets the panel layout for the applet. As each object need to reference the methods of the other objects, the references are passed during the instantiation and initialization of each object. The init method also reads the weight parameter from the html and passes it to the simulation object. This is not done very elegantly - failure to specify a weight parameter results in a null pointer exception. The start method starts the simulation thread and the stop method stops it.

The simulation object is an instance of the Simulation class. It holds the variables that specify the state of the system and has a run method to implement the movement of the knot toward a stable position. When a stable position is reached, the run method suspends itself. Most other methods in the class are to allow safe access to the state variables.

The diagram object is an instance of the DiagramPanel class. It draws the diagram display and is a subclass of the Panel class. Double buffering is implemented in the paint method. I don't know how to create the second image object at a more convenient point so there is a check to see whether it exists at the start of paint; a call to paintSetup is made if it doesn't. diagram also implements event driven user interaction by overriding the handleEvent method. When an object (anchor or knot) is picked up the simulation thread is suspended; when an object is dropped the simulation thread is resumed if the system is in an unstable position.

The controls object is an instance of the ControlPanel class. It draws the control panel to the right of the display. The angle display is updated by simulation when running. Otherwise, the angle and weight may be set by the user and values are read by simulation. Events generated by setting the angle (via text entry or one of the push-buttons) or the weight result in a update call to diagram.

Bugs

There is an error in the Java API description of the Math.atan2 method. The documentation describes it as follows:

atan2

  public static double atan2(double a,
                             double b)
Converts rectangular coordinates (a, b) to polar (r, theta). This method computes the phase theta by computing an arc tangent of b/a in the range of -Pi to Pi.
Parameters:
a - an assigned value
b - an assigned value
Returns:
the polar coordinates (r, theta).
In fact, atan2 returns arctan(a/b) which would be the value of theta for the rectangular coordinates (b, a). The actual implementation follows the C function.

[ Up | Contacts ]


This page is maintained by Simeon Warner
Last updated 20 May 1996