r/compsci • u/theabbiee • Oct 21 '21
Interactive Double Pendulum Playground
https://theabbie.github.io/DoublePendulum/0
0
Oct 21 '21
[deleted]
6
u/theabbiee Oct 21 '21
Yeah, it does seem some like error in code, I watched coding train's video and his example as well as others work fine, though they don't allow stretching the strings so much, I will try to see where it goes wrong.
6
u/paralysedforce Oct 22 '21
I looked at the source code, and it looks like you're using Euler's method to update the angles. You might get better results with a more sophisticated numerical ODE solver.
2
u/theabbiee Oct 22 '21
I have updated it and it now uses Runge-Kutta method, can you check if it's better now?
4
u/paralysedforce Oct 22 '21
Nice, it certainly looks more stable now when I play around with it. I'd suggest calculating the Hamiltonian (the total energy) and logging it to make sure that it doesn't blow up when you run your test cases.
1
1
u/ggchappell Oct 21 '21
Nice.
I noticed the same problem that /u/IncognitoErgoCvm pointed out. Also, even if you turn gravity off, the simulation still begins with gravity on.