Simple Pendulum Simulation
Coding Challenge #159
Choo choo! In this challenge, I build on chapter 3 (Oscillating Motion) of the Nature of Code series and simulate a simple pendulum in p5.js via angular acceleration.
Topics
- 0:00 - Choo choo!! 2021 Coding Challenge!
- 0:43 - Code! Drawing a bob and an arm.
- 1:08 - Explain! How are we going to think about this?
- 2:55 - Code! Add our main variables.
- 3:20 - Explain! How do we figure out where the bob is? Trigonometry is the answer!
- 4:39 - Code! Use the polar coordinates formulas we just worked out.
- 6:30 - Code! Let's use angular motion!
- 7:55 - Explain! What is the force of the pendulum? Trigonometry is the answer!
- 10:46 - Code! Add the pendulum force.
- 12:04 - Whoops! Correction on why we multiply by -1.
- 13:34 - Code! Add -1 to the formula.
- 13:57 - Whoops! I figured out some things that I never really understood.
- 14:24 - Code! Correct the 3 step process.
- 15:32 - Something doesn't feel quite right.
- 16:59 - Explain! Angular acceleration relates to the arm length!
- 18:58 - Code! Let's divide by length.
- 19:54 - Code! You could add some damping.
- 20:21 - Ideas! What could you do next?
Community Contributions
- Pendulum on a cart with PID controller by Ewoud Dronkert (Source Code)
- Colourful Pendulum in CodePen by Indrayudh Chakraborty (Source Code)
- Simple Pendulum Simulation using Python by Karan Kinariwala (Source Code)
- Up Down Left Right by Josh Kenzer (Source Code)
- Pendulum website by Sarvagya singh (Source Code)
You can also add your own version! (See how)
Links discussed in this coding challenge
Videos discussed in this coding challenge
- Polar Coordinates - Nature of Code by The Coding Train
- 3.2 Angular Motion - Nature of Code by The Coding Train
- Double Pendulum - Coding Challenge #93 by The Coding Train
- Coding Train Live! (February 6th 2021) by The Coding Train