Collisions Without a Physics Library! (Coding Challenge 184)

Subscribers:
1,740,000
Published on ● Video Link: https://www.youtube.com/watch?v=dJNFPv9Mj-Y



Duration: 31:05
160,824 views
5,728


What happens when two circles collide in a p5.js canvas? In this video, I examine the math and implement idealized elastic collisions in a JavaScript physics simulation. This video supplements the Nature of Code book series in Chapter 6 which uses 3rd party physics libraries to handle collisions rather than a direct implementation. Code: https://thecodingtrain.com/challenges/184-elastic-collisions

๐Ÿš€ Watch this video ad-free on Nebula https://nebula.tv/videos/codingtrain-coding-challenge-184-elastic-collisions

p5.js Web Editor Sketches:
๐Ÿ•น๏ธ Elastic Collisions: https://editor.p5js.org/codingtrain/sketches/3DrBb8LCp
๐Ÿ•น๏ธ Elastic Collisions - Quadtree: https://editor.p5js.org/codingtrain/sketches/z8n19RFz9

๐ŸŽฅ Previous: https://youtu.be/p7IGZTjC008?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
๐ŸŽฅ All: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH

References:
๐Ÿ“• The Nature of Code: https://natureofcode.com/
๐Ÿ›’ Pre-order The Nature of Code: https://nostarch.com/nature-code
๐Ÿ”— Elastic Collision: https://en.wikipedia.org/wiki/Elastic_collision
๐Ÿ“ƒ 2-Dimensional Elastic Collisions without Trigonometry: https://www.vobarian.com/collisions/2dcollisions2.pdf
๐Ÿ“ƒ Elastic Collisions Formula Derivation: https://dipamsen.github.io/notebook/collisions.pdf

Related Coding Challenges:
๐Ÿš‚ https://youtu.be/IIrC5Qcb2G4
๐Ÿš‚ https://youtu.be/OJxEcs0w_kE
๐Ÿš‚ https://youtu.be/PoW8g67XNxA
๐Ÿš‚ https://youtu.be/h5ZNcAPXxew

Timestamps:
0:00 Introduction
0:20 The Nature of Code book
1:22 Review background material
4:15 Collision Resolution
5:42 Start Coding
8:48 Add collide() function
10:17 Momentum and kinetic energy
14:15 Line of impact
16:44 Add the formulas
21:25 Simplify the code
22:57 Check for overlap
24:31 Check the particle's kinetic enery
25:48 Fix error
27:30 Add more particles
30:11 Optimizations
30:50 Outro

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

๐Ÿš‚ Website: https://thecodingtrain.com/
๐Ÿ‘พ Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide
๐Ÿšฉ Suggest Topics: https://github.com/CodingTrain/Suggestion-Box
๐Ÿ’ก GitHub: https://github.com/CodingTrain
๐Ÿ’ฌ Discord: https://thecodingtrain.com/discord
๐Ÿ’– Membership: http://youtube.com/thecodingtrain/join
๐Ÿ›’ Store: https://standard.tv/codingtrain
๐Ÿ–‹๏ธ Twitter: https://twitter.com/thecodingtrain
๐Ÿ“ธ Instagram: https://www.instagram.com/the.coding.train/

๐ŸŽฅ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
๐ŸŽฅ https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA

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

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

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

#collisions #physicssimulation #p5js #javascript
=====================================================