Now let's try out some of these ideas with the flexible rope.
We'll fix both ends of that rope
and want to see what the equilibrium shape is going to be
under the influence of gravity.
The obvious choice of finite elements is springs.
Springs of a given rest length, so that the potential energy of each spring
amounts to 1/2 times the spring constant times the square of the extension of the spring,
which is the distance between the two endpoints minus the rest length of the string.
To model the mass of that rope, we attach mass points to these strings.
Of course, these mass points carry potential energy due to gravity.
Given the constants that we provide, compute the potential energy of that rope.
The one end of that rope will be fixed at x = 0, y = 0.
The other end of that rope will be fixed at x = 1.3 m and y = 0.4 m.
Our code starts with a random initialization
and then applies a pretty simplistic strategy to minimize the energy.
For a certain number of times it's going to pick one of the masses
and change the position of that mass point by a random vector.
If the energy decreases, it keeps that new position.
If it doesn't, it returns to the position before.
Very simple, but highly inefficient.