I have written a very basic simulation of a pendulum. I used the equation α = -g/l * sin(φ)
. I set g/l
to 50, so I expect to get a period of 0.89 seconds (Using the formula 2π*√(l/g)
). However, I get a period of around 6.5 seconds. The relevant code part is
let ang_acc = - 50.0 * pendulum.angle.to_radians().sin();
pendulum.ang_vel += ang_acc * dt;
pendulum.angle += pendulum.ang_vel * dt;
The complete code is on GitHub. I tried to make it as basic as possible and commented everything important.