title

2.6 Mutual Attraction - The Nature of Code

description

Finishing off Chapter 2 on forces, let's look at an "N-Body Simulation" where all movers experience gravitational attraction with all other movers! https://thecodingtrain.com/tracks/the-nature-of-code-2/noc/2-forces/6-mutual-attraction
p5.js Web Editor Sketches:
đšī¸ Mutual Attraction (N-Body): https://editor.p5js.org/codingtrain/sketches/bEt7eLZ6Y
đšī¸ Mutual Attraction (N-Body) with Barnes Hut: https://editor.p5js.org/codingtrain/sketches/joXNoi9WL
đĨ Previous video: https://youtu.be/EpgB3cNhKPM?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
đĨ Next video: https://youtu.be/DMg-WRfNB60?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
đĨ All videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZV4yEcW3uDwOgGXKUUsPOM
Links discussed in this video:
đ Newton's law of universal gravitation (Wikipedia): https://en.wikipedia.org/wiki/Newton's_law_of_universal_gravitation
đ Nature of Code Book - 2.10 Everything Attracts (or Repels) Everything: https://natureofcode.com/book/chapter-2-forces/#210-everything-attracts-or-repels-everything
đ p5.Vector rotate(): https://p5js.org/reference/#/p5.Vector/rotate
đ N-Body Choreographies research paper by Montaldi and Steckles: https://personalpages.manchester.ac.uk/staff/j.montaldi/Choreographies/about.html
đ N-Body Choreographies animation tool by Dan Gries: https://personalpages.manchester.ac.uk/staff/j.montaldi/Choreographies/
Other videos mentioned in this video:
đĨ 2.5 Gravitational Attraction - The Nature of Code: https://youtu.be/EpgB3cNhKPM
đĨ 2.1 Simulating Forces: Gravity and Wind - The Nature of Code: https://youtu.be/Uibl0UE4VH8
đĨ 5.1 Autonomous Steering Agents - The Nature of Code: https://youtu.be/P_xJMH8VvAE
đĨ 3.1 Angles and Rotation - The Nature of Code: https://youtu.be/DMg-WRfNB60
đĨ Coding Challenge #98.1 - Quadtree: https://youtu.be/OJxEcs0w_kE
Timestamps:
0:00 Introducing Today's Topic
0:30 Recap Single attractor system
1:20 The two body problem
2:21 Euler Integration
2:53 Other integration options
4:00 Coding 2-body simulation
7:56 The three body problem
8:15 Coding 3-body simulation
9:04 Refactoring for n-body
10:48 Adding a fourth mover
11:38 Looking at initial states
12:03 Shape 1: donut
13:33 The p5 Vector rotate() function
16:12 Trying out different variations
17:34 Looking at efficiency
19:10 Adding the sun
20:46 Looking at other examples
21:21 Exercise for viewers
22:09 Invite to chapter 3 and goodbye
đ Website: http://thecodingtrain.com/
đž Share Your Creation! https://thecodingtrain.com/Guides/community-contribution-guide.html
đŠ Suggest Topics: https://github.com/CodingTrain/Rainbow-Topics
đĄ GitHub: https://github.com/CodingTrain
đŦ Discord: https://discord.gg/hPuGy2g
âĒ Nebula: https://go.nebula.tv/codingtrain
đ Membership: http://youtube.com/thecodingtrain/join
đ Store: https://standard.tv/codingtrain
đ Books: https://www.amazon.com/shop/thecodingtrain
đī¸ Twitter: https://twitter.com/thecodingtrain
đ¸ Instagram: https://www.instagram.com/the.coding.train/
đĨ Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
đĨ Intro to Programming: 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/website/issues/new

detail

{'title': '2.6 Mutual Attraction - The Nature of Code', 'heatmap': [{'end': 451.365, 'start': 433.065, 'weight': 0.713}, {'end': 1162.044, 'start': 1138.486, 'weight': 1}, {'end': 1256.608, 'start': 1233.517, 'weight': 0.719}], 'summary': 'Delves into mutual attraction, gravitational forces, and the two-body problem, emphasizing the formula for gravitational attraction, the concept of two-body problem, and its solvability with mathematical equations and calculus. it also discusses using euler integration for creative coding and explores methods like leapfrog, verlet, and runge-kutta integration for improved results in solving scenarios like the two body, three body, and n body problems, demonstrating the simulation of a three-body problem using attraction forces and motion visualization, showcasing balanced forces, loop calculations, and visual representation of the chaotic system with interesting results.', 'chapters': [{'end': 145.37, 'segs': [{'end': 51.845, 'src': 'embed', 'start': 22.02, 'weight': 2, 'content': [{'end': 31.104, 'text': 'This is the example from the end of the last video where every one of these orbiting circles is attracted to that pink circle in the center.', 'start': 22.02, 'duration': 9.084}, {'end': 35.405, 'text': "Let's review very quickly that formula for gravitational attraction.", 'start': 31.544, 'duration': 3.861}, {'end': 42.909, 'text': 'So in the case here, we have two bodies.', 'start': 39.807, 'duration': 3.102}, {'end': 47.401, 'text': "I'm going to call them body 1 and body 2.", 'start': 44.229, 'duration': 3.172}, {'end': 48.482, 'text': 'They each have a mass.', 'start': 47.401, 'duration': 1.081}, {'end': 51.845, 'text': 'That is what is represented by m1 and m2 in this formula.', 'start': 48.962, 'duration': 2.883}], 'summary': 'Orbiting circles attracted to center, discussing formula for gravitational attraction with two bodies and their masses.', 'duration': 29.825, 'max_score': 22.02, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc22020.jpg'}, {'end': 145.37, 'src': 'embed', 'start': 99.288, 'weight': 0, 'content': [{'end': 108.276, 'text': "If we have two bodies like one and two here, and there are no other forces in the environment, there's no air resistance, there's no other things,", 'start': 99.288, 'duration': 8.988}, {'end': 115.363, 'text': 'other bodies, the pure essence of just the gravitational forces that these two bodies exert on each other,', 'start': 108.276, 'duration': 7.087}, {'end': 120.668, 'text': 'and what motion would occur is known as the two-body problem.', 'start': 115.363, 'duration': 5.305}, {'end': 123.924, 'text': "One thing I'd like to mention.", 'start': 123.004, 'duration': 0.92}, {'end': 130.886, 'text': 'if you were about to go and do some research about the two body problem, you would discover that it is a solved problem.', 'start': 123.924, 'duration': 6.962}, {'end': 138.208, 'text': 'That the paths of the motion of these bodies can be computed precisely with mathematical equations,', 'start': 131.466, 'duration': 6.742}, {'end': 142.25, 'text': 'starting with the formula for gravitational attraction and the equations of motion.', 'start': 138.208, 'duration': 4.042}, {'end': 145.37, 'text': 'To execute those solutions requires calculus.', 'start': 142.47, 'duration': 2.9}], 'summary': 'The two-body problem is a solved problem with precise mathematical equations requiring calculus.', 'duration': 46.082, 'max_score': 99.288, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc99288.jpg'}], 'start': 0.694, 'title': 'Mutual attraction and the n-body problem', 'summary': 'Delves into mutual attraction, gravitational forces, and the two-body problem, emphasizing the formula for gravitational attraction, the concept of two-body problem, and its solvability with mathematical equations and calculus.', 'chapters': [{'end': 145.37, 'start': 0.694, 'title': 'Mutual attraction and the n-body problem', 'summary': 'Discusses mutual attraction, gravitational forces, and the two-body problem, highlighting the formula for gravitational attraction, the concept of two-body problem, and the solvability with mathematical equations and calculus.', 'duration': 144.676, 'highlights': ['The paths of the motion of two bodies can be computed precisely with mathematical equations, as the two-body problem is a solved problem, requiring calculus for execution.', 'The concept of the two-body problem arises when there are no other forces in the environment, and the pure essence of gravitational forces exerted by two bodies on each other dictates the motion.', 'The formula for gravitational attraction involves the masses of the bodies (m1 and m2), the vector pointing from one body to the other (r), and the unit vector describing the direction of the gravitational force.']}], 'duration': 144.676, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc694.jpg', 'highlights': ['The paths of the motion of two bodies can be computed precisely with mathematical equations, as the two-body problem is a solved problem, requiring calculus for execution.', 'The concept of the two-body problem arises when there are no other forces in the environment, and the pure essence of gravitational forces exerted by two bodies on each other dictates the motion.', 'The formula for gravitational attraction involves the masses of the bodies (m1 and m2), the vector pointing from one body to the other (r), and the unit vector describing the direction of the gravitational force.']}, {'end': 428.001, 'segs': [{'end': 197.968, 'src': 'embed', 'start': 145.871, 'weight': 0, 'content': [{'end': 149.912, 'text': 'And here we are in the nature of code, creative coding, fun time landscape.', 'start': 145.871, 'duration': 4.041}, {'end': 156.265, 'text': 'where, instead of evaluating the scenario through solving differential equations,', 'start': 150.802, 'duration': 5.463}, {'end': 163.208, 'text': "I'm using this technique that I've described previously as Euler integration, where we just use large time,", 'start': 156.265, 'duration': 6.943}, {'end': 170.292, 'text': 'steps the frames of our animation and we add acceleration into the velocity and the velocity into the position.', 'start': 163.208, 'duration': 7.084}, {'end': 179.774, 'text': 'If we wanted to investigate some more sophisticated methods for doing performing this kind of integration,', 'start': 173.649, 'duration': 6.125}, {'end': 183.036, 'text': 'we could look at something called leapfrog integration.', 'start': 179.774, 'duration': 3.262}, {'end': 185.618, 'text': 'We could look at Verlet integration.', 'start': 183.817, 'duration': 1.801}, {'end': 188.881, 'text': 'We could look at Runge-Kutta integration.', 'start': 186.619, 'duration': 2.262}, {'end': 197.968, 'text': 'And I would love to hear from you if you try to execute a version of whatever I make in this video with one of these styles of integration.', 'start': 191.383, 'duration': 6.585}], 'summary': 'Introduction to euler integration for creative coding and animation, with mention of alternative methods like leapfrog, verlet, and runge-kutta integration.', 'duration': 52.097, 'max_score': 145.871, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc145871.jpg'}, {'end': 246.347, 'src': 'embed', 'start': 218.502, 'weight': 5, 'content': [{'end': 223.987, 'text': "Other nice thing about what we're doing here is, I'm foreshadowing some things that are come later in the nature of code,", 'start': 218.502, 'duration': 5.485}, {'end': 226.249, 'text': 'in particular in the autonomous agents chapter.', 'start': 223.987, 'duration': 2.262}, {'end': 231.374, 'text': 'Because one of the things I want to look at are scenarios like flocking simulations,', 'start': 226.55, 'duration': 4.824}, {'end': 236.059, 'text': 'where every agent moving around a system interacts with every other agent.', 'start': 231.374, 'duration': 4.685}, {'end': 240.223, 'text': "That's what we are beginning to do here, but with gravitational attraction.", 'start': 236.499, 'duration': 3.724}, {'end': 246.347, 'text': "But I think I've shown off my outdoor, it's not really outdoor, I'm like slightly inside this garage, whiteboard enough.", 'start': 240.703, 'duration': 5.644}], 'summary': 'Foreshadowing flocking simulations in nature of code, with gravitational attraction, and autonomous agents chapter.', 'duration': 27.845, 'max_score': 218.502, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc218502.jpg'}, {'end': 275.705, 'src': 'embed', 'start': 252.171, 'weight': 3, 'content': [{'end': 261.757, 'text': 'So in looking at this example, while if I wanted to do a two body simulation, I could reduce it to just two separate variables, mover one, mover two.', 'start': 252.171, 'duration': 9.586}, {'end': 265.94, 'text': "I would like to stick with the array because that's going to help me later.", 'start': 262.838, 'duration': 3.102}, {'end': 270.543, 'text': "So what I'm going to do is just change the array to having just two elements in it.", 'start': 266.3, 'duration': 4.243}, {'end': 275.705, 'text': "And I'm also going to get rid of this idea of an attractor.", 'start': 271.563, 'duration': 4.142}], 'summary': 'Reducing the simulation to two separate variables in an array and eliminating the concept of an attractor for future optimization.', 'duration': 23.534, 'max_score': 252.171, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc252171.jpg'}], 'start': 145.871, 'title': 'Creative coding and autonomous agents simulation', 'summary': 'Discusses using euler integration for creative coding and explores methods like leapfrog, verlet, and runge-kutta integration for improved results in solving scenarios like the two body, three body, and n body problems. it also covers the transition from an attractor-based simulation to a two-body problem simulation, demonstrating the coding process and the interaction between the two bodies with specific initial velocities.', 'chapters': [{'end': 217.762, 'start': 145.871, 'title': 'Euler integration for creative coding', 'summary': 'Discusses using euler integration for creative coding, with a possibility of exploring more sophisticated methods like leapfrog, verlet, and runge-kutta integration for improved results in solving scenarios like the two body, three body, and n body problems.', 'duration': 71.891, 'highlights': ['Explaining the technique of Euler integration for creative coding, using large time steps in animation and adding acceleration into velocity and velocity into position. Technique of Euler integration, use of large time steps, and adding acceleration into velocity.', 'Suggesting the exploration of more advanced integration methods like leapfrog, Verlet, and Runge-Kutta for potential improvements in the results of the examples. Mention of advanced integration methods for potential improvement.', 'Encouraging the audience to try executing the examples with different styles of integration and share the results for feedback. Encouragement for audience to try different integration styles and share feedback.']}, {'end': 428.001, 'start': 218.502, 'title': 'Autonomous agents simulation', 'summary': 'Discusses the transition from an attractor-based simulation to a two-body problem simulation, demonstrating the coding process and the interaction between the two bodies with specific initial velocities.', 'duration': 209.499, 'highlights': ['The chapter discusses the transition from an attractor-based simulation to a two-body problem simulation. The speaker explains the elimination of the attractor concept and the focus on two bodies interacting with specific initial velocities.', 'Demonstrating the coding process for interaction between the two bodies with specific initial velocities. The speaker showcases the coding process for two bodies attracting each other with specific initial velocities, emphasizing the visual representation and the resultant patterns.', 'Foreshadowing flocking simulations in the nature of code, particularly in the autonomous agents chapter. The speaker hints at future content related to flocking simulations and interactions between autonomous agents in the nature of code.']}], 'duration': 282.13, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc145871.jpg', 'highlights': ['Explaining the technique of Euler integration for creative coding, using large time steps in animation and adding acceleration into velocity and velocity into position.', 'Suggesting the exploration of more advanced integration methods like leapfrog, Verlet, and Runge-Kutta for potential improvements in the results of the examples.', 'Encouraging the audience to try executing the examples with different styles of integration and share the results for feedback.', 'The chapter discusses the transition from an attractor-based simulation to a two-body problem simulation.', 'Demonstrating the coding process for interaction between the two bodies with specific initial velocities.', 'Foreshadowing flocking simulations in the nature of code, particularly in the autonomous agents chapter.']}, {'end': 707.598, 'segs': [{'end': 463.612, 'src': 'heatmap', 'start': 433.065, 'weight': 0, 'content': [{'end': 434.326, 'text': "They're moving quite slowly.", 'start': 433.065, 'duration': 1.261}, {'end': 438.309, 'text': "So a couple of things I could do is let's give them a higher initial velocity.", 'start': 434.346, 'duration': 3.963}, {'end': 444.717, 'text': "And let's increase the strength of the gravitational force.", 'start': 440.291, 'duration': 4.426}, {'end': 451.365, 'text': 'And we get this nice, beautiful, like sort of like repeating circular dance.', 'start': 446.943, 'duration': 4.422}, {'end': 455.547, 'text': "Now again, I'm not solving for the precise equations of motion.", 'start': 451.745, 'duration': 3.802}, {'end': 463.612, 'text': "I'm not using the proper units of measurement that map to actual celestial bodies, in terms of their distance and mass,", 'start': 455.948, 'duration': 7.664}], 'summary': 'Adjusting initial velocity and gravitational force results in a repeated circular dance.', 'duration': 30.547, 'max_score': 433.065, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc433065.jpg'}, {'end': 563.055, 'src': 'embed', 'start': 504.232, 'weight': 1, 'content': [{'end': 506.894, 'text': "And I'm going to give it no velocity just for the moment.", 'start': 504.232, 'duration': 2.662}, {'end': 509.396, 'text': "It's not participating in this at all.", 'start': 507.554, 'duration': 1.842}, {'end': 514.479, 'text': 'Now what I need to do is I need to say, OK, 0 attracts 1.', 'start': 509.776, 'duration': 4.703}, {'end': 515.559, 'text': '0 attracts 2.', 'start': 514.479, 'duration': 1.08}, {'end': 518.001, 'text': '1 attracts 0 and 2.', 'start': 515.559, 'duration': 2.442}, {'end': 525.18, 'text': 'And 2 attracts 0 and 1.', 'start': 518.001, 'duration': 7.179}, {'end': 536.75, 'text': 'amazingly, the body in the center is not moving because its attraction forces are perfectly balanced between those two particles on the outside.', 'start': 525.18, 'duration': 11.57}, {'end': 538.011, 'text': "that's kind of unbelievable.", 'start': 536.75, 'duration': 1.261}, {'end': 539.533, 'text': "that's really cool.", 'start': 538.011, 'duration': 1.522}, {'end': 542.155, 'text': "let's just push it slightly to the left.", 'start': 539.533, 'duration': 2.622}, {'end': 545.869, 'text': 'So this is not super sustainable.', 'start': 544.329, 'duration': 1.54}, {'end': 552.572, 'text': "If I want to have four movers, five movers, I can't keep individually assigning which ones attract the other ones.", 'start': 545.889, 'duration': 6.683}, {'end': 555.112, 'text': 'But I can write a loop that handles this.', 'start': 552.772, 'duration': 2.34}, {'end': 559.414, 'text': 'Now, I have a loop down here to update and show all the different movers.', 'start': 555.413, 'duration': 4.001}, {'end': 563.055, 'text': 'I want to keep the force calculations in a separate loop.', 'start': 559.754, 'duration': 3.301}], 'summary': 'Simulation of balanced attraction forces between particles, demonstrating stability and need for automated force calculations.', 'duration': 58.823, 'max_score': 504.232, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc504232.jpg'}, {'end': 696.374, 'src': 'embed', 'start': 664.153, 'weight': 3, 'content': [{'end': 667.258, 'text': "And I think there's a lot for you to sort of try and continue playing with.", 'start': 664.153, 'duration': 3.105}, {'end': 671.885, 'text': 'Just out of curiosity, let me go back to making them random.', 'start': 667.598, 'duration': 4.287}, {'end': 681.966, 'text': "So we can see with them random, I'm getting quite an unstable chaotic system.", 'start': 677.543, 'duration': 4.423}, {'end': 688.169, 'text': "But I think what I'm trying to emphasize here is that, by thinking about the initial starting conditions of the system,", 'start': 682.106, 'duration': 6.063}, {'end': 696.374, 'text': 'the results that you get might have some symmetry or sort of character to them that you could take advantage of for a particular kind of design.', 'start': 688.169, 'duration': 8.205}], 'summary': 'Exploring chaotic systems with random initial conditions for potential design advantages.', 'duration': 32.221, 'max_score': 664.153, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc664153.jpg'}], 'start': 431.423, 'title': 'Simulating orbital dynamics and three-body problem simulation', 'summary': 'Explores simulating orbital dynamics by adjusting initial velocity and gravitational force strength, resulting in visually coherent circular dance. additionally, it demonstrates the simulation of a three-body problem using attraction forces and motion visualization, showcasing balanced forces, loop calculations, and visual representation of the chaotic system with interesting results.', 'chapters': [{'end': 477.559, 'start': 431.423, 'title': 'Simulating orbital dynamics', 'summary': 'Explores simulating orbital dynamics by adjusting initial velocity and gravitational force strength, resulting in a visually coherent circular dance, albeit without precise equations or proper units.', 'duration': 46.136, 'highlights': ['By adjusting the initial velocity and increasing the strength of the gravitational force, a visually coherent circular dance can be achieved.', 'The simulation lacks precise equations of motion and proper units of measurement mapping to actual celestial bodies.', 'The author expresses a desire to continue playing with the parameters and variables of the system indefinitely.']}, {'end': 707.598, 'start': 477.939, 'title': 'Three-body problem simulation', 'summary': 'Demonstrates the simulation of a three-body problem using attraction forces and motion visualization, showcasing the balanced forces, loop calculations, and visual representation of the chaotic system with interesting results.', 'duration': 229.659, 'highlights': ['The balanced forces between the three bodies result in the stationary position of the third body in the center, showcasing the equilibrium achieved with the attraction forces. The body in the center remains stationary due to perfectly balanced attraction forces between the two particles on the outside.', 'Demonstrating the usage of loops to handle force calculations and update different movers, providing a scalable approach for simulating multiple movers in the system. The implementation of loops enables efficient handling of force calculations and updating different movers, offering scalability for simulating numerous movers in the system.', "Visual representation of the chaotic system with interesting results, emphasizing the impact of initial starting conditions on the system's symmetry and design potential. The simulation showcases the chaotic motion of the three bodies, highlighting the potential symmetry and design characteristics influenced by the initial starting conditions of the system."]}], 'duration': 276.175, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc431423.jpg', 'highlights': ['By adjusting the initial velocity and increasing the strength of the gravitational force, a visually coherent circular dance can be achieved.', 'The balanced forces between the three bodies result in the stationary position of the third body in the center, showcasing the equilibrium achieved with the attraction forces.', 'Demonstrating the usage of loops to handle force calculations and update different movers, providing a scalable approach for simulating multiple movers in the system.', "Visual representation of the chaotic system with interesting results, emphasizing the impact of initial starting conditions on the system's symmetry and design potential."]}, {'end': 978.204, 'segs': [{'end': 768.923, 'src': 'embed', 'start': 734.554, 'weight': 3, 'content': [{'end': 737.715, 'text': 'I want to place the mover objects anywhere inside of this shaded area.', 'start': 734.554, 'duration': 3.161}, {'end': 743.558, 'text': 'Now, ultimately, if you happen to skip ahead and watch a bunch of videos in chapter 3,', 'start': 737.855, 'duration': 5.703}, {'end': 753.482, 'text': "you're going to learn all about polar coordinates and various trigonometric functions that could make doing this in a spiral pattern and all sorts of fun possibilities happen for you.", 'start': 743.558, 'duration': 9.924}, {'end': 757.704, 'text': "But right now, I'm going to make use of the p5 vector function random2D.", 'start': 753.682, 'duration': 4.022}, {'end': 768.923, 'text': 'What this is going to allow me to do is create a vector that points in any random direction, like these five here.', 'start': 760.779, 'duration': 8.144}], 'summary': 'Using p5 vector function random2d to create vectors in random directions for mover objects within a shaded area.', 'duration': 34.369, 'max_score': 734.554, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc734554.jpg'}, {'end': 812.81, 'src': 'embed', 'start': 780.189, 'weight': 0, 'content': [{'end': 790.524, 'text': 'then I can set those random vectors magnitude to a random length between 100 and 150..', 'start': 780.189, 'duration': 10.335}, {'end': 797.686, 'text': 'Offsetting from the center of the window, then I have mover objects that are placed randomly around here.', 'start': 790.524, 'duration': 7.162}, {'end': 799.546, 'text': "Let's try just that first.", 'start': 798.026, 'duration': 1.52}, {'end': 804.728, 'text': "So instead of setting the x, y as random numbers individually, let's create a random vector.", 'start': 800.226, 'duration': 4.502}, {'end': 812.81, 'text': 'Set the magnitude to between 100 and 150.', 'start': 807.388, 'duration': 5.422}], 'summary': 'Creating random vectors with magnitude between 100 and 150 for object placement.', 'duration': 32.621, 'max_score': 780.189, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc780189.jpg'}, {'end': 900.654, 'src': 'embed', 'start': 840.265, 'weight': 1, 'content': [{'end': 844.928, 'text': 'So now I have five mover objects anywhere inside this donut.', 'start': 840.265, 'duration': 4.663}, {'end': 851.988, 'text': "If I were to say 500, we can see clearly they're all starting just like I mapped out on the whiteboard.", 'start': 845.088, 'duration': 6.9}, {'end': 854.429, 'text': "Let's see what happens if I let it just run.", 'start': 852.828, 'duration': 1.601}, {'end': 860.173, 'text': 'Explosive total chaos.', 'start': 857.371, 'duration': 2.802}, {'end': 864.216, 'text': "Let's consider one example mover.", 'start': 861.754, 'duration': 2.462}, {'end': 870.66, 'text': 'It just happens to be placed here with this vector mark noting its location.', 'start': 866.517, 'duration': 4.143}, {'end': 876.224, 'text': 'What if I gave it an initial velocity that is perpendicular to this vector?', 'start': 871.16, 'duration': 5.064}, {'end': 891.388, 'text': 'So, no matter where it starts, its initial velocity is always sending it in the direction which would be essentially tangent to this circle.', 'start': 877.93, 'duration': 13.458}, {'end': 894.31, 'text': "Now, I'm starting to use a lot of terms like perpendicular.", 'start': 891.448, 'duration': 2.862}, {'end': 895.731, 'text': 'Its angle is 90 degrees.', 'start': 894.37, 'duration': 1.361}, {'end': 896.472, 'text': "It's tangent.", 'start': 895.811, 'duration': 0.661}, {'end': 900.654, 'text': 'Again, follow into chapter 3, and all will be revealed.', 'start': 896.852, 'duration': 3.802}], 'summary': 'Five mover objects in donut, 500 units, chaotic movement, tangent direction.', 'duration': 60.389, 'max_score': 840.265, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc840265.jpg'}, {'end': 978.204, 'src': 'embed', 'start': 949.861, 'weight': 2, 'content': [{'end': 953.964, 'text': "So now that position vector is copied into velocity before I've resized it.", 'start': 949.861, 'duration': 4.103}, {'end': 959.529, 'text': "And then after I've resized position, I can take velocity and rotate it by pi divided by 2.", 'start': 954.285, 'duration': 5.244}, {'end': 961.41, 'text': "That's 90 degrees.", 'start': 959.529, 'duration': 1.881}, {'end': 963.132, 'text': "And let's see what happens.", 'start': 962.031, 'duration': 1.101}, {'end': 969.116, 'text': "Oh, I named it VEL, and I didn't rename it here.", 'start': 966.294, 'duration': 2.822}, {'end': 976.963, 'text': "Well, we've still got quite a jumbled mess of stuff going on.", 'start': 973.6, 'duration': 3.363}, {'end': 978.204, 'text': "Let's take out the trails.", 'start': 977.003, 'duration': 1.201}], 'summary': 'Copying position vector to velocity, resizing position, and rotating velocity by 90 degrees.', 'duration': 28.343, 'max_score': 949.861, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc949861.jpg'}], 'start': 707.878, 'title': 'Using p5 vector function for random movement', 'summary': 'Covers creating random vectors with magnitudes between 100 and 150 using the p5 vector function, placing mover objects within a donut-shaped area, resulting in chaotic movement.', 'chapters': [{'end': 753.482, 'start': 707.878, 'title': 'Initial positions and velocities for end body simulation', 'summary': 'Discusses creating an array of mover objects in an end body simulation and setting up their initial positions inside a shaded area in a spiral pattern using polar coordinates and trigonometric functions.', 'duration': 45.604, 'highlights': ['The chapter demonstrates the process of setting up initial positions and velocities for an array of mover objects in an end body simulation.', 'It mentions the use of polar coordinates and trigonometric functions to create a spiral pattern for placing the mover objects.']}, {'end': 870.66, 'start': 753.682, 'title': 'Using p5 vector function for random movement', 'summary': 'Discusses using the p5 vector function random2d to create random vectors, setting their magnitude between 100 and 150, and placing mover objects randomly within a specified donut-shaped area, resulting in total chaos.', 'duration': 116.978, 'highlights': ['Creating random vectors with magnitude between 100 and 150 The chapter demonstrates the creation of random vectors with magnitudes between 100 and 150 to set the movement range for the mover objects.', 'Placing mover objects randomly within a donut-shaped area The discussion includes placing mover objects randomly within a specified donut-shaped area, leading to chaotic movement patterns.', 'Using the p5 vector function random2D for random movement The chapter explains the utilization of the p5 vector function random2D to enable random movement for the mover objects.']}, {'end': 978.204, 'start': 871.16, 'title': 'Vector rotation and initial velocity', 'summary': "Explores the concept of vector rotation using the p5 vector class, demonstrating how a vector's initial velocity can be modified by a 90-degree rotation, preparing for further exploration in chapter 3.", 'duration': 107.044, 'highlights': ["The use of the rotate function in the p5 vector class to modify a vector's direction by 90 degrees or pi/2 radians, demonstrating the concept of vector rotation.", 'Demonstration of copying the position vector into the velocity vector and then rotating the velocity vector by 90 degrees, showcasing the practical application of vector rotation in altering initial velocity direction.', 'Explanation of using an initial velocity that is always perpendicular to the vector, emphasizing the significance of tangent direction in the context of vector motion.']}], 'duration': 270.326, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc707878.jpg', 'highlights': ['Creating random vectors with magnitude between 100 and 150 to set the movement range for mover objects.', 'Placing mover objects randomly within a donut-shaped area, leading to chaotic movement patterns.', 'Demonstration of copying the position vector into the velocity vector and then rotating the velocity vector by 90 degrees.', 'The use of polar coordinates and trigonometric functions to create a spiral pattern for placing the mover objects.', 'Explanation of using an initial velocity that is always perpendicular to the vector, emphasizing the significance of tangent direction in vector motion.']}, {'end': 1344.942, 'segs': [{'end': 1051.049, 'src': 'embed', 'start': 1018.523, 'weight': 2, 'content': [{'end': 1024.146, 'text': 'And this is what I was hoping to see, this almost undulating, spiraling galaxy-like formation.', 'start': 1018.523, 'duration': 5.623}, {'end': 1026.686, 'text': "Let's give myself more space.", 'start': 1025.106, 'duration': 1.58}, {'end': 1030.45, 'text': 'Spread those movers a little further out from the center.', 'start': 1028.008, 'duration': 2.442}, {'end': 1036.333, 'text': 'Give them an even higher initial velocity.', 'start': 1034.271, 'duration': 2.062}, {'end': 1044.52, 'text': "Let's try 250.", 'start': 1039.935, 'duration': 4.585}, {'end': 1045.622, 'text': "I'm quite enjoying this.", 'start': 1044.52, 'duration': 1.102}, {'end': 1051.049, 'text': "And let's create a little bit more variation now in the mass and initial velocity.", 'start': 1046.162, 'duration': 4.887}], 'summary': 'Experimenting with galaxy-like formation, adjusting initial velocity and mass for variation.', 'duration': 32.526, 'max_score': 1018.523, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc1018523.jpg'}, {'end': 1138.266, 'src': 'embed', 'start': 1091.424, 'weight': 0, 'content': [{'end': 1096.536, 'text': '350 times 350 is? 122,500 computational cycles.', 'start': 1091.424, 'duration': 5.112}, {'end': 1106.055, 'text': "Let's go back down to 200.", 'start': 1096.556, 'duration': 9.499}, {'end': 1111.38, 'text': "And you can see that's probably about the limit that I can get just with the way that I've written the code.", 'start': 1106.055, 'duration': 5.325}, {'end': 1121.508, 'text': 'Now there are many efficiencies that you could add to a system like this to be able to increase the number of mover objects that you can draw and the amount of forces that you could calculate.', 'start': 1111.86, 'duration': 9.648}, {'end': 1127.994, 'text': 'Probably the most well-known technique for optimizing an n-body simulation like this is the Barnes-Hutt simulation.', 'start': 1121.909, 'duration': 6.085}, {'end': 1132.679, 'text': "I've covered something quite close to this in a previous coding challenge where I looked at something called a quadtree.", 'start': 1128.354, 'duration': 4.325}, {'end': 1138.266, 'text': 'So you could go back and look at the quadtree coding challenge and bring the quadtree code into this example.', 'start': 1133, 'duration': 5.266}], 'summary': 'Simulation code can handle 200 mover objects; optimizations like barnes-hutt technique and quadtree can improve performance.', 'duration': 46.842, 'max_score': 1091.424, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc1091424.jpg'}, {'end': 1162.044, 'src': 'heatmap', 'start': 1138.486, 'weight': 1, 'content': [{'end': 1145.915, 'text': "In fact, I will make sure to do that and include a quadtree Barnes-Hutt version of this n-body simulation linked from the video's description.", 'start': 1138.486, 'duration': 7.429}, {'end': 1149.817, 'text': "So right now, I don't know what I'm going to show you here, but here you're seeing the result of that.", 'start': 1146.215, 'duration': 3.602}, {'end': 1156.821, 'text': "One thing I'm curious to try is what happens if I bring back, somewhat artificially, this idea of an attractor,", 'start': 1150.237, 'duration': 6.584}, {'end': 1162.044, 'text': "a stationary object that's maybe with a larger mass, positioned right in the center of the canvas.", 'start': 1156.821, 'duration': 5.223}], 'summary': 'N-body simulation with quadtree barnes-hutt version and attractor experiment.', 'duration': 23.558, 'max_score': 1138.486, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc1138486.jpg'}, {'end': 1264.972, 'src': 'heatmap', 'start': 1233.517, 'weight': 0.719, 'content': [{'end': 1239.123, 'text': "It's very hard to stop tweaking all the parameters, but I'm going to settle on this as kind of the example that I'm going to release.", 'start': 1233.517, 'duration': 5.606}, {'end': 1246.572, 'text': 'I reduced it just down to 10, and I constrained the ranges of masses and velocities to just create this stable system.', 'start': 1239.203, 'duration': 7.369}, {'end': 1256.608, 'text': 'A wonderful reference that I would encourage you to take a look at is the paper Classification of Symmetry Groups for Planar End Body Choreographies by James Moltaldi and Katrina Steckles.', 'start': 1247.185, 'duration': 9.423}, {'end': 1264.972, 'text': 'In the paper, they demonstrate a set of initial conditions for end body systems that create these symmetrical and stable choreographies.', 'start': 1257.409, 'duration': 7.563}], 'summary': 'System parameters reduced to 10, creating stable system. refer to paper for symmetrical and stable choreographies.', 'duration': 31.455, 'max_score': 1233.517, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc1233517.jpg'}, {'end': 1317.838, 'src': 'embed', 'start': 1287.837, 'weight': 5, 'content': [{'end': 1292.681, 'text': "What kinds of initial conditions can you create in the system that I've set up?", 'start': 1287.837, 'duration': 4.844}, {'end': 1295.303, 'text': 'And how might you visualize those simulations?', 'start': 1292.981, 'duration': 2.322}, {'end': 1297.524, 'text': 'with color, with trails, with shapes?', 'start': 1295.303, 'duration': 2.221}, {'end': 1299.326, 'text': 'So many possibilities.', 'start': 1297.844, 'duration': 1.482}, {'end': 1307.371, 'text': 'I should mention that this particular interactive simulation, these paths are drawn with precise mathematical equations,', 'start': 1300.046, 'duration': 7.325}, {'end': 1310.633, 'text': "not with a physics simulation like I'm doing here.", 'start': 1307.371, 'duration': 3.262}, {'end': 1317.838, 'text': 'And ultimately, my physics simulation, as I talked about earlier in the video, is a very crude one with these large time steps.', 'start': 1310.953, 'duration': 6.885}], 'summary': 'Creating and visualizing various initial conditions in an interactive simulation, drawn with precise mathematical equations and using a crude physics simulation with large time steps.', 'duration': 30.001, 'max_score': 1287.837, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc1287837.jpg'}], 'start': 980.12, 'title': 'N-body simulation challenges', 'summary': 'Explores the challenges of an n-body simulation, demonstrating the impact of computational cycles on performance and presenting techniques for optimization, including the barnes-hutt simulation and quadtree implementation.', 'chapters': [{'end': 1051.049, 'start': 980.12, 'title': 'Tinkering with forces and velocities', 'summary': 'Explores the manipulation of mass, gravity, and velocity to create an undulating, spiraling galaxy-like formation, increasing the number of movers, spreading them further out, and adjusting their initial velocity.', 'duration': 70.929, 'highlights': ['Observing an undulating, spiraling galaxy-like formation by manipulating the mass, gravity, and velocity of the movers.', 'Increasing the number of movers and spreading them further out from the center.', 'Adjusting the initial velocity of the movers, increasing it to 250 units.']}, {'end': 1344.942, 'start': 1055.455, 'title': 'N-body simulation challenges', 'summary': 'Explores the challenges of an n-body simulation, demonstrating the impact of computational cycles on performance and presenting techniques for optimization, including the barnes-hutt simulation and quadtree implementation.', 'duration': 289.487, 'highlights': ['The computational complexity of checking every mover against every other mover in an n-body simulation is demonstrated with 350 circles requiring 122,500 computational cycles.', 'The Barnes-Hutt simulation and quadtree implementation are highlighted as well-known techniques for optimizing an n-body simulation, offering the potential to increase the number of mover objects and the amount of forces that can be calculated.', 'The exploration of initial conditions for end body systems and the encouragement to visualize simulations with color, trails, and shapes are proposed as exercises for the viewer, along with references to relevant research papers and interactive demonstrations.']}], 'duration': 364.822, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/GjbKsOkN1Oc/pics/GjbKsOkN1Oc980120.jpg', 'highlights': ['The Barnes-Hutt simulation and quadtree implementation are highlighted as well-known techniques for optimizing an n-body simulation, offering the potential to increase the number of mover objects and the amount of forces that can be calculated.', 'The computational complexity of checking every mover against every other mover in an n-body simulation is demonstrated with 350 circles requiring 122,500 computational cycles.', 'Observing an undulating, spiraling galaxy-like formation by manipulating the mass, gravity, and velocity of the movers.', 'Increasing the number of movers and spreading them further out from the center.', 'Adjusting the initial velocity of the movers, increasing it to 250 units.', 'The exploration of initial conditions for end body systems and the encouragement to visualize simulations with color, trails, and shapes are proposed as exercises for the viewer, along with references to relevant research papers and interactive demonstrations.']}], 'highlights': ['The formula for gravitational attraction involves the masses of the bodies (m1 and m2), the vector pointing from one body to the other (r), and the unit vector describing the direction of the gravitational force.', 'The concept of the two-body problem arises when there are no other forces in the environment, and the pure essence of gravitational forces exerted by two bodies on each other dictates the motion.', 'Delves into mutual attraction, gravitational forces, and the two-body problem, emphasizing the formula for gravitational attraction, the concept of two-body problem, and its solvability with mathematical equations and calculus.', 'Explaining the technique of Euler integration for creative coding, using large time steps in animation and adding acceleration into velocity and velocity into position.', 'The balanced forces between the three bodies result in the stationary position of the third body in the center, showcasing the equilibrium achieved with the attraction forces.', 'The Barnes-Hutt simulation and quadtree implementation are highlighted as well-known techniques for optimizing an n-body simulation, offering the potential to increase the number of mover objects and the amount of forces that can be calculated.']}