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 `!!!'.
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.
atan2
public static double atan2(double a,
double b)