theabbie / DoublePendulum

Double Pendulum Playground
https://theabbie.github.io/DoublePendulum/
MIT License
48 stars 4 forks source link

Simulation breaks when the two pendulums are on opposing sides of the anchor. #2

Open ocket8888 opened 2 years ago

ocket8888 commented 2 years ago
  1. Lift the middle ball up and to the right, above the anchor point.
  2. When you let go, the simulation begins, so wait for the ball to come back to about the same point where you just dropped it, then pause.
  3. raise the lower pendulum up and to the left, across the anchor point from the first pendulum. Looks like its height relative to the the other pendulum is irrelevant.
  4. Let go, watch as the simulated pendulums speed up over time, seemingly violating conservation of energy/momentum, until they reach a speed the simulation can no longer handle and the pendulum becomes just a line that extends outside the screen space. This also seemed to break the rendering of the pause button, for some reason (although I could still click it to pause afterwards).

Update: actually it looks like the line was just a coincidence the first time. After reproducing, I found that the pendulum lines appeared in three separate places, two of which don't seem possible:

image

ocket8888 commented 2 years ago

oh, actually, four places. It's up behind the pause button too.

theabbie commented 2 years ago

Thanks for letting me know, appreciate it, I will see what's the issue

gregreen commented 2 years ago

The non-conservation of energy is probably due to the fact that you're using Euler integration.

You can get rid of this behavior by using a symplectic integrator, such as the Verlet method (look specifically at the "Velocity Verlet" section). Symplectic integrators approximately conserve energy, and are generally more stable.

theabbie commented 2 years ago

@gregreen oh okay, thanks, will check out

ocket8888 commented 2 years ago

Sorry, one would think that a guy with degrees in both physics and compsci should be well-equipped to diagnose this, but it turns out that I don't remember anything they taught me in Intermediate Mechanics - a class where I literally had to build a double-pendulum simulation.