The core of the program is a trigonometric formula that converts the force acting on a given bead into two normal forces on the two supporting contacts. The force comes partly from the weight of the bead and partly from other beads that may be resting on it. Thus the force need not be straight downward.
The program starts by placing fixed beads along the bottom and sides. All beads have a radius that varies randomly over a ten percent range. After these beads are placed, the program waits for a mouse click. When the mouse is clicked, the program notes the cursor position and adds a bead resting on the bead clicked. The bead is placed as close as possible to the cursor, then it "rolls down" until it makes contact with another supporting bead. If the click is not over a bead, or if the newly added bea d would overlap an existing bead, no bead is added.
Once a new bead is added the forces caused by its weight are computed. First, the "core formula" mentioned above calculates the two contact forces supporting the added bead. Next the supporting beads of these beads are determined. We call this the sec ond generation of supporting beads. Each supporting bead has a new load, which must be supplied by its supporting contacts. These contact forces are calculated for all the second-generation beads using the core formula. Then the third-generation beads supporting the second-generation beads are determined, and the newly added forces are computed for their contacts. This process proceeds until a generation where all the beads are fixed beads along the bottom and sides.
Next, thin lines are drawn to indicate the forces that have been computed. There is a line for each contact affected by the newly added bead. The lines point to the two supporting contacts of each bead. Green means a compressive force; orange means a t ensile force. The length of each line is an increasing function of the force, but not a linear function. A contact force equal to the weight of the added bead would create a line halfway to the center of the supporting contact. A tenfold decrease in fo rce reduces the length by about 1/8 of this length.
Finally, the contact forces from the newly added bead are added to the pre-existing contact forces to give the total force on each contact. The least compressive of these forces is determined and drawn as a thick line using the scheme above. Blue means compressive; red means tensile.
If the mouse is moved over a bead after this process, two thick lines are drawn from the center of that bead to show the total force on its two supporting contacts. The lengths and colors follow the scheme above.
If the undo button is clicked, the last added bead and its associated forces are removed. Only one bead can be removed in this way.
If the "divide weights by 2" button is clicked, all the contact forces for the current beads will be divided by 2. In effect, the weight of all current beads has been divided by 2. However any newly added bead has its full weight. By clicking this butt on several times, the existing beads can be made virtually weightless relative to a newly added bead. Thus if the newly added bead creates a tensile force, the other beads contribute virtually no pre-existing force that might compensate for it.
Force, bead position and contact angle information are stored in double-precision real arrays in the Java program.
Force calculations are accurate even when there are tensile contacts and the word "avalanche" appears.