This simulation shows a single mass on a spring, which is connected to the ceiling. The mass is able to move in 2 dimensions, and gravity operates. Does the motion look random to you? Watch the graph for a while and you'll see its actually an intricate pattern.
You can change gravity, mass, spring stiffness, and friction (damping). You can drag the mass with your mouse to change the starting position.
The math behind the simulation is shown below. Also available are: open source code, documentation and a simple-compiled version which is more customizable.
An immoveable (but draggable) anchor point has a spring and bob hanging below and swinging in two dimensions. Regard the bob as a point mass. Define the following variables:
Define some constants:
Note that for this simulation the vertical dimension increases downwards. We'll need the standard unit vectors i, j . We use bold and overline to indicate a vector.
There are three vector forces acting on the bob:
Summing these forces and using Newton's second law we get:
m a = F_{gravity} + F_{spring} + F_{damping}
m (a_{x} i + a_{y} j) = m g j − k S (sin θ i + cos θ j) − b (v_{x} i + v_{y} j)
We can write the horizontal and vertical components of the above as separate equations. This gives us two simultaneous equations. We also divide each side by m .
a_{x} = − ^{k}⁄_{m} S sin θ − ^{b}⁄_{m} v_{x} | (1a) |
a_{y} = g − ^{k}⁄_{m} S cos θ − ^{b}⁄_{m} v_{y} | (1b) |
These are the equations of motion. It only remains to show how S sin θ and S cos θ are functions of the position of the bob. The displacement of the spring S is the current length of the spring minus the rest length.
S = L − R | (2) |
From the pythagorean theorem we can get the length of the spring L in terms of from the position of the bob, u , and the position of the anchor point, T .
$$L = \sqrt{(u_x - T_x)^2 + (u_y - T_y)^2} \tag{3}$$
The sine and cosine of the angle θ are:
sin θ = (u_{x} − T_{x})/L | (4a) |
cos θ = (u_{y} − T_{y})/L | (4b) |
To solve the equations of motion numerically, so that we can drive the simulation, we use the Runge Kutta method for solving sets of ordinary differential equations. Since the Runge-Kutta method only works with first-order differential equations, we convert the two second-order equations (1) to the following four first-order equations.
u_{x}' = v_{x}
u_{y}' = v_{y}
v_{x}' = − ^{k}⁄_{m} S sin θ − ^{b}⁄_{m} v_{x}
v_{y}' = g − ^{k}⁄_{m} S cos θ − ^{b}⁄_{m} v_{y}
Keep in mind that S sin θ and S cos θ are functions of the position of the bob, u_{x}, u_{y} , as given in equations (2-4).
This web page was first published April 2001.