Live data from Hacker News

Double Pendulum in fewer than 100 lines of JavaScript

physicsandbox.com

51–55 of 55 posts

Re: Double Pendulum in fewer than 100 lines of JavaScript

#51

Interesting thing about the double pendulum - it is very difficult to get the numerical integration correct, even using very high order integrators like RK4. The simple Euler integrator used here has no hope of getting it right (not a criticism, just an observation!) The problem is that the double pendulum equations (in fact, any equations of motion derived from a Hamiltonian) have symplectic structure, i.e. they hav…

The Udacity course on numerical diffy-Q covers some of this.

https://www.udacity.com/course/cs222

I wrote a simple N-body simulator game after viewing the course, although I'm still having issues with the energy conservation.

https://github.com/madengr/nbody

Re: Double Pendulum in fewer than 100 lines of JavaScript

#52

Very nice simulation you've got there! I also did a triple pendulum in JS a while ago. Quite a lot more than 100 lines of code, though. The equations of motion alone take up lots and again lots of space. (Imagine typing them in! I don't even dare to think about adding a fourth degree of freedom) http://users.jyu.fi/~samakapa/triplependulum/ My dynamics course teacher actually showed that the double pendulum can be li…

... that pendulum doesn't mirror reality at all. It's as though the first mass is constantly being accelerated by something other than gravity.

Re: Double Pendulum in fewer than 100 lines of JavaScript

#53
post #52

Very nice simulation you've got there! I also did a triple pendulum in JS a while ago. Quite a lot more than 100 lines of code, though. The equations of motion alone take up lots and again lots of space. (Imagine typing them in! I don't even dare to think about adding a fourth degree of freedom) http://users.jyu.fi/~samakapa/triplependulum/ My dynamics course teacher actually showed that the double pendulum can be li…

... that pendulum doesn't mirror reality at all. It's as though the first mass is constantly being accelerated by something other than gravity.

First mass counting from which end? The masses are accelerated by each other as there are rigid rods between them.

The lack of friction and the perfectly rigid coupling between the joints might be what makes it seem lacking reality. If we'd extend the chain with more links, the motion of the outermost mass would become more and more unpredictable due to extreme acceleration.

Of course I might have made a mistake somewhere, but I checked that energy is conserved between the frames of the animation (excluding minor energy drift due to the numerical integration).

Re: Double Pendulum in fewer than 100 lines of JavaScript

#54
post #3

Cool. Feature request: mount the pivot on a programmable cart. It'd be fun to write software to balance the double pendulum. e.g. https://www.youtube.com/watch?v=B6vr1x6KDaY and, balancing a triple pendulum: https://www.youtube.com/watch?v=cyN-CRNrb3E

Whoa. This is blowing my mind. It is seriously amazing that this exists.
Post reply on HN