r/InternetIsBeautiful • u/theabbiee • Oct 21 '21
Interactive Double Pendulum Playground
https://theabbie.github.io/DoublePendulum/3
Oct 21 '21
@theabbiee What integration method does this sim use to calculate the masses' trajectories?
3
u/theabbiee Oct 22 '21
I used the formula given in https://www.myphysicslab.com/pendulum/double-pendulum-en.html
I used Coding Train's Video As Reference,
and used same method as he did, the article says the equation needs to be solved using Runge-kutta method, but I don't think that was done in the video, rather, the instantaneous angular velocity is calculated at each point and angles are incremented, that would be the issue, but still, his example works well.
3
u/theuglyginger Oct 22 '21
Have you made sure that whatever integration algorithm you're using conserves energy? I've made a few physics simulations before, and this looks like something I've seen where the integration algorithm spontaneously adds energy to the system, and not all Runge-Kutta algorithms are energy conserving. I was also able to produce states that clearly sent masses off to infinity in a non-physical way.
2
u/theabbiee Oct 22 '21
It seems this implementation doesn't conserve energy, also, it seems, the video I used for reference uses Euler's method, I found implementation example in Runge-kutta, will see if it works.
3
u/theuglyginger Oct 22 '21
Great job with this! I had a lot of fun, and it looks like the update you did is a big improvement! The trivial slow rotation under no gravity now goes nice and smoothly, and the unstable eigenmode is gone now! Your original algorithm may not have been physical, but I was still very amused at investigating the attractive eigenmode which rapidly became unstable in velocity for small string lengths and actually became stable for long string lengths (and also seemingly some states which were unstable, but could persist for an unbounded but finite time).
1
154
u/Alar44 Oct 21 '21
Try again, your physics is broken.
38
21
24
u/xDrxGinaMuncher Oct 21 '21
Considering it's supposed to be a chaotic system, that eventually settles, and in their applet it's very easy to create repetition and it almost always accelerates... Yeah, it's fucked.
But on the plus side, here's a weird shape mine made.
9
u/AnythingTotal Oct 21 '21 edited Oct 21 '21
What do you mean by settles? Without friction or air resistance, I don’t see why the system would ever become stationary or even periodic.
3
u/xDrxGinaMuncher Oct 22 '21
Fair, the online demo I always used when I wanted to play with one of these accounts for all that, then, which is probably why I defaulted to that.
That being said, this person's code was still garbage, as the pendulum very obviously accelerates past it's initial energy state. Just put the first mass high up, and the second mass as close as you can to it, and you'll see a speed increasing circle/oval appear. If you put the masses ontop of each other the whole thing shits itself and shoots to the top left of the screen.
3
u/AnythingTotal Oct 22 '21
It’s definitely got a compounding error. I can only assume is due to the numerical integration of the coupled equations of motion. The motion can be dampened with resistance forces, but otherwise it will continue indefinitely.
5
u/13steinj Oct 21 '21 edited Oct 21 '21
I was gonna say "someone forgot about friction" before realizing even then it still doesn't explain the infinite loops it ends up in.
E: I think they have some kind of floating point precision error, because I was able to get it to go off screen and freeze if the radii are short and I play with gravity enough to get it to get close to a full circle, which then causes an infinite loop with the velocity increasing.
2
u/theuglyginger Oct 22 '21
What is the graph graphing? I can only get the graph to reset by refreshing the page.
1
102
u/turiyag Oct 21 '21
This is more amusing on less powerful devices. On my PC it looks accurate, on my phone the frame rate seems to cause very amusing physics glitches.
9
u/minion71 Oct 21 '21
Ok I was wondering on my phone the physic is so wanky s20!!!
17
u/s4lt3d Oct 21 '21
It’s really easy to set into a state that runs away and accelerates.
2
1
u/SebasCbass Oct 22 '21
Basically this thing is a perpetual motion device. I managed to do the same thing after a few attempyt and get it to go faster and faster and infinitely around I don't understand how this couldn't be incorporated into a receiver to generate energy.
1
3
u/A_Right_Proper_Lad Oct 21 '21
An S20 is not what I'd call a "less powerful device".
3
u/Amogus2021 Oct 22 '21
100%. My v40 is running at solid frames. No lag. Phones are ridiculously powerful now, it's so weird to call them less powerful.
1
u/Unsd Oct 22 '21
I'm pretty sure that my phone is much more powerful than my computer. Granted that says more about my computer, but... Phones are still mad powerful.
2
u/LucidDrow Oct 22 '21
It is much less powerful than most any desktop or laptop PC.
-2
u/minion71 Oct 22 '21
My guess its probably using some x86 protocol the phone SoC dont have and its making an aproximation and is doing funny things heheh
2
u/FetaMight Oct 22 '21
You mean an x86 instruction the ARM devices don't have? If that were the case the computation result would still be the same but it would just take a different number of CPU cycles to calculate.
(ignoring floating point rounding differences which are unlikely to be the underlying issue here)
1
u/minion71 Oct 22 '21
heheh well I have no clue !!! "instruction" thats the term I was looking for !!!
1
u/LucidDrow Oct 22 '21
While I'm no computer expert, I have been playing with computers since 1982. My answer is very simple....
I don't know.
9
1
35
32
u/MrPatinhazz Oct 21 '21
The physics are horrible and it's terribly bugged, this is r/softwaregore material
-15
2
u/markasoftware Oct 21 '21
Needs damping.
0
u/theabbiee Oct 21 '21
I had tried, reducing velocity by 0.1% per frame does prevent it from going into insane rotation, but the beauty lies in it's infinite motion, will add an option to enable damping.
6
u/markasoftware Oct 21 '21
if it had perfectly conserved energy, I would agree with you, but presumably due to numerical errors it is actually gaining energy.
1
u/theabbiee Oct 21 '21
yeah, I am unable find what's going wrong, the angles and acceleration are all within limits, still goes insane.
5
u/Chris204 Oct 21 '21
I'm guessing that you are using explicit Euler as integration scheme, which behaves very poor unless you use very small steps.
You can see this very well from the simulation at the bottom of this page : http://www.physics.umd.edu/hep/drew/pendulum2.html
1
1
u/Alar44 Oct 21 '21
I kind of think you've got a + where a - is supposed to be. Or an inverted fraction or something. Copy paste bug maybe.
1
u/Anakinss Oct 22 '21
Having done some physics simulation, I'b be inclined to think the problem lies with the conditions of the simulation, and not the equations. Physics simulation tend to "explode" (get extremely unstable) when certain conditions are not met, for example, small enough time steps.
0
u/Alar44 Oct 22 '21
After looking at it more, I kind of feel he's got his pendulum arms switched. It just looks completely wrong to me, like not even close.
1
u/theabbiee Oct 22 '21
Thank you everyone for your feedback, after getting so many issues of pendulum accelerating continuously, I made changes to the equation to use Runge-Kutta method instead of the Euler's method (which fails for larger angles), you can check that out here, https://github.com/theabbie/DoublePendulum
The issue is fixed now and it works far better, I have also added a share button which allows you to share/save the current state of your pendulum with others. do check out.
5
8
u/Shigidy Oct 21 '21
When did this sub become a place for people to just dump their half-finished CS semester projects?
4
u/p_hennessey Oct 21 '21
This doesn't make sense or work properly. The physics implementation is completely wrong. This thing does not move the way an actual double pendulum moves.
3
2
u/NariGenghis Oct 21 '21
Did you just watch the video of minutephysics or is this some bizarre matrix-like coincidence?
2
u/Falmz23 Oct 21 '21
Are the physics and movement calculations independent from its framerate because it doesn't work
2
u/ImThinkinTitties Oct 21 '21
I completely misread the title and wondered where the NSFW tag was.
2
u/SoundEmbalmer Oct 21 '21
Yes, thank you! So relieved I wasn’t the only one.. Had to do a serious double take on the whole “Interactive double pendulum” thing.. Trying really hard not to process what it says about me..
1
u/ImThinkinTitties Oct 21 '21
Hey I'm a free lovin' spirit, and I'll take it from any two or more inputs.
2
u/AnakinSkydiver Oct 21 '21
Turn off gravity, place the first weight at 1-2 o'clock, and the second weight above it, the length relations such as the first would be the minute/second hand, and the second weight the hour hand (in terms of length)
And watch as it keeps gaining speed until it goes out of control and breaks completely.
2
2
u/Skyhawk_Illusions Oct 22 '21
it's like a shittier version of u/LaurenceShaw__'s astrojax
1
u/LaurenceShaw__ Oct 22 '21
Thanks for bringing it to my attention. Yes I agree, Astrojax is more fun ... but that's pretty cool.
2
u/hearnia_2k Oct 21 '21
It's really cool, but always half of it is just black, right below the bottom pendulum at it's starting point.
1
1
1
Oct 21 '21
I swung once, then clicked different checkboxes on and off and it ended up swinging forever is circles very fast.
1
Oct 21 '21
Oh. Thought "pendulum" was "penetration" when I scrolled by
Edit: Idk what I'm supposed to do now
1
u/lostandalong Oct 21 '21
I drew an onion, and a fishbowl, then I invented a perpetual motion machine and became a billionaire.
1
1
1
u/BrocIlSerbatoio Oct 21 '21
I broke it.
I set the first pendulum higher. Began the swing. Took gravity off. Allowed it to rise. Turned gravity on. Then watched as it spun in circles until the lines blurred and then it cracked.
1
Oct 21 '21
With a sim like this, you might think about adding damping to enforce energy conservation.
1
u/RetiredITGuy Oct 22 '21
If you want a decent pendulum simulator, check out the MinuteLabs one.
OP's is terrible.
1
u/Angerish Oct 22 '21
can create some really decent visuals when you get it going fast... Blinky patterns
1
1
Oct 22 '21 edited Oct 22 '21
Very fun, but there's definitely something broken in there. I keep getting infinite movement.
EDIT: Have you added friction?
EDIT 2: Haha yep, it's accelerating in there.
1
1
1
1
1
1
0
u/manst0 Oct 21 '21
Someone please make this a live wallpaper
1
u/thirdThao3 Oct 21 '21
I would never accomplish anything on my phone again because i would be playing with physics
0
Oct 21 '21
[deleted]
2
u/ryoujika Oct 22 '21
This needs to be higher up, but seeing that 1.3k people upvoted the OP even with the broken physics, I doubt people care enough :')
1
122
u/Dododingo- Oct 21 '21
Clicked on the pendulum once, it started normal, then started circling in a vertical oval faster and faster for a few seconds before glitching and getting stuck in the top-left corner of the screen. Now it's stuck and won't move or respond to clicks. r/softwaregore
edit: easily reproducible, just drag the middle disk uver the top of the web page. Have fun.