Coding Challenge 93: Double Pendulum

915,647
0
Published 2018-02-13
In this coding challenge, I create a double pendulum simulation in Processing. Code: thecodingtrain.com/challenges/93-double-pendulum

šŸ•¹ļø p5.js Web Editor Sketch: editor.p5js.org/codingtrain/sketches/jaH7XdzMK

šŸŽ„ Previous video: Ā Ā Ā ā€¢Ā CodingĀ ChallengeĀ #92:Ā XORĀ ProblemĀ Ā 
šŸŽ„ Next video: Ā Ā Ā ā€¢Ā CodingĀ ChallengeĀ #94:Ā 2048Ā -Ā PartĀ 1Ā Ā 
šŸŽ„ All videos: Ā Ā Ā ā€¢Ā CodingĀ ChallengesĀ Ā 

References:
šŸ”“ Physics Lab Double Pendulum: www.myphysicslab.com/pendulum/double-pendulum-en.hā€¦

Videos:
šŸš‚ Pendulum Simulation: Ā Ā Ā ā€¢Ā 3.4:Ā PendulumĀ SimulationĀ -Ā TheĀ Nature...Ā Ā 
šŸ”“ Coding Train Live 120: Ā Ā Ā ā€¢Ā LiveĀ StreamĀ #120:Ā MNISTĀ andĀ PendulumsĀ Ā 

Related Coding Challenges:
šŸš‚ #86 Cube Wave by Bees and Bombs: Ā Ā Ā ā€¢Ā CodingĀ ChallengeĀ #86:Ā CubeĀ WaveĀ byĀ Be...Ā Ā 
šŸš‚ #159 Simple Pendulum Simulation: Ā Ā Ā ā€¢Ā CodingĀ ChallengeĀ #159:Ā SimpleĀ Pendulu...Ā Ā 

Timestamps:
0:00:00 Double Pendulum Simulation
0:03:45 Creating The Double Pendulum
0:08:35 Adding The Tracing of The Path
0:12:51 Implementing The Double Pendulum Formulas
0:24:45 Visualizing It
0:28:21 Adding Damping
0:29:16 Conclusions And Suggestions

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound

šŸš‚ Website: thecodingtrain.com/
šŸ‘¾ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
šŸš© Suggest Topics: github.com/CodingTrain/Suggestion-Box
šŸ’” GitHub: github.com/CodingTrain
šŸ’¬ Discord: thecodingtrain.com/discord
šŸ’– Membership: youtube.com/thecodingtrain/join
šŸ›’ Store: standard.tv/codingtrain
šŸ–‹ļø Twitter: twitter.com/thecodingtrain
šŸ“ø Instagram: www.instagram.com/the.coding.train/

šŸŽ„ Coding Challenges: Ā Ā Ā ā€¢Ā CodingĀ ChallengesĀ Ā 
šŸŽ„ Intro to Programming: Ā Ā Ā ā€¢Ā StartĀ learningĀ here!Ā Ā 

šŸ”— p5.js: p5js.org/
šŸ”— p5.js Web Editor: editor.p5js.org/
šŸ”— Processing: processing.org/

šŸ“„ Code of Conduct: github.com/CodingTrain/Code-of-Conduct

This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/nā€¦

#doublependulum #pendulumharmonicmotion #processing

All Comments (21)
  • @sarath_sajan
    13:15 Note: the following proof is trivial and has been left as an exercise to the reader
  • @missingsemi
    ā€œG is the universal gravitational constant, I assume. Thatā€™s just gonna be one.ā€
  • @RedTriangle53
    Fun fact in case nobody else has mentioned it: updating the positions using the "current velocity" vs the previous one changes the numerical method from Euler's method to the Euler-Cromer method, which is quite a lot more accurate. The regular Euler method is prone to inadvertently increasing the energy of the system, while the Euler-Cromer method conserves energy quite decently. The two methods seem almost identical, but the behind the scenes math is quite interesting and shows that they are actually of different orders.
  • @Phi1618033
    "Okay, I'm gonna see if I can just copy and paste this enormous differential equation right into my code."
  • To those who want to make this simulation more real do this. Currently Dan is setting g = 1. Although its far from the actual value the simulation looks very real. This is because one second in the simulation is one frame. And by default processing or p5.js is set to 60 fps. This means when one second passes in real world, 60 seconds would have passed in the simulation world. Hence the correct value of g would be 9.8/ ( 60 * 60 ) . There's still one more thing to adjust. The masses are actually in kilograms hence you should set the value of bob masses to around 0.05 which is 50 grams. Also, the lengths are in meters so make that they aren't very large.
  • I really REALLY laughed when the pendulum just started warping into another dimension at 12:30 "See, this is kind of the idea"
  • @photon2724
    i have no idea wats going on. yet im enjoying this video.
  • @ayjaygame
    I never knew i could be so engaged and laugh at someone doing something like this. Great video! :)
  • @DowzerWTP72
    I'm so happy you've done this; I started making one of these in P5 using a class, and I just figured you'd use basic Trig to calculate the angles. Had literally no idea the lre was a huge algorithm derived for it! Gonna give this a looking soon!
  • @matthimf
    24:10 you are changing the integration method from simple explicit Euler to symplectic Euler which is numerically much more stable.
  • @cashel1111
    this is the first of your videos i have seen, i am so glad people actally go through these sort of things for others to see keep up the good work :)
  • I think a cool feature to add would be a fade of the trace line, so as a segment of line is drawn, say 5 seconds later it begins to fade, so you only ever have the last 5 or so seconds of trace at any given time
  • @TheDyingPlant
    Youā€™re one of those special people in the world that make it a better place. You can always tell, and it just radiates from you.
  • First video I watch from this genius. Youā€™re funny as hell, your channelā€™s gonna get me hooked. Thanks.
  • Idk why this was recommenced to me, I never even coded, but you're so full of energy and entertaining, thumbs up dude
  • @klivecorps
    THIS IS A PERFECT EXAMPLE OF HOW TO DO AND HANDLE COMPLEX PROJECTS AND COMPLEX ALGORITHM. YOU'RE GREAT!!
  • you are a blessing !!!! a true blessing. I cant thank you enough for what you are doing.
  • @toastrecon
    Pretty cool! A few things: the dampening should be a function of velocity, proportional using some constant. It would be harder/maybe fun to calculate the forces along the bars and have them extend elastically under the load.