Тёмный

Planet Simulation In Python - Tutorial 

Tech With Tim
Подписаться 1,5 млн
Просмотров 494 тыс.
50% 1

Welcome back to another tutorial video! In this video I am going to be showing you how to make a planet simulation using Python! The goal of this tutorial is to simulate the orbits of different planets around the sun using real astronomical values! We're also going to apply the force of gravity on each of the planets so we get an accurate elliptical orbit! I hope you enjoy!
💻 Thanks to BackTrace for sponsoring this video! Build better games with less bugs today for FREE by signing up for a developer account: hubs.la/Q012hTT00
💻 ProgrammingExpert is the best platform to learn how to code and become a software engineer as fast as possible! Check it out here: programmingexpert.io/tim and use code "tim" for a discount!
📄 Resources 📄
Inspiration For This Video: fiftyexamples.readthedocs.io/...
Code In This Video: github.com/techwithtim/Python...
Fix Pip (Windows): • How to Install Pygame ...
Fix Pip (Mac): www . • How to Install Pygame ...
⭐️ Timestamps ⭐️
00:00 | Planet Simulation
01:15 | Sponsor
02:12 | Setup & Installation
03:46 | Pygame Window Setup
09:28 | Creating Planets
18:50 | Initializing Planets (Using Real Values)
27:33 | Moving Planets Explanation (Math & Physics)
36:45 | Implementing Movement Physics
51:58 | Drawing Orbits
55:38 | Drawing Distance To Sun
59:18 | Conclusion
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
👕 Merchandise: teespring.com/stores/tech-wit...
📸 Instagram: / tech_with_tim
📱 Twitter: / techwithtimm
⭐ Discord: / discord
📝 LinkedIn: / tim-ruscica-82631b179
🌎 Website: techwithtim.net
📂 GitHub: github.com/techwithtim
🔊 Podcast: anchor.fm/tech-with-tim
🎬 My RU-vid Gear: www.techwithtim.net/gear/
💵 One-Time Donations: www.paypal.com/donate?hosted_...
💰 Patreon: / techwithtim
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
⭐️ Tags ⭐️
-Tech With Tim
-Planet Simulation
-Planet Simluation In Python
-How to Simulate Planets
-Python Simulation Tutorial
⭐️ Hashtags ⭐️
#TechWithTim #Python #PlanetSimulation

Опубликовано:

 

27 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 438   
@TechWithTim
@TechWithTim 2 года назад
Hey guys! Glad so many of you are enjoying this topic. Just wanted to note that I made a bunch of small physics/math errors in this video and I am by no means a physicist. Some people have politely pointed out the flaws in the simulation and that it is indeed a very rough approximation. Regardless, I think there is still a ton of value here and you can tweak/fix some parts to make it more accurate 👍
@randomdude7386
@randomdude7386 2 года назад
I dont think I could spot any major errors on either the maths or physics side in your explanations, but some times I as a physics major felt like you had no idea how to bring it accross as you seemed frightened of the possibility of saying something factually incorrect as the important part in this is, to bring the fundamental concept accross to those who came here not knowing how any of this worked. TLDR: Next time you do something like this, maybe try to be more relaxed and think less about the possibility of details being of in the grand scheme of things, as this has not stopped you from building this audience, as mistakes are human and it matters how we address them
@HypnosisBear
@HypnosisBear 2 года назад
The thumbnail is click bait.😑 I thought you are gonna make a 3D simulation.
@mr.whiteboard6357
@mr.whiteboard6357 2 года назад
@@HypnosisBear Yeah me too
@Hiyouri005
@Hiyouri005 2 года назад
HEY CAN YOU POST CODE TOO//
@rafigasparyan6584
@rafigasparyan6584 2 года назад
@@Hiyouri005 the code, along with all of the resources he used and credited, are in the description (press SHOW MORE, the button is under the channel name and subscribe line/section).
@lissankoirala
@lissankoirala 2 года назад
It's not the first time so pretty sure it's not just a coincidence. I was thinking about this project and here you go 3 days later posting the exact thing I want. You really seem to know what your audience needs, thanks Tim!
@harshmirdhwal
@harshmirdhwal 2 года назад
It's called manifestation bro
@heelercs
@heelercs 2 года назад
@@harshmirdhwal Lol, sure bro
@ryanchowdhary965
@ryanchowdhary965 2 года назад
Ai maybe??
@harshmirdhwal
@harshmirdhwal 2 года назад
@@ryanchowdhary965 force greater than ai
@speedybenzedrex6786
@speedybenzedrex6786 2 года назад
tim hacked u and used alll your data to create the perfect video for you
@vishsinghania
@vishsinghania 2 года назад
amazing tutorial 👍 just a correction at 45:00 F = m times a (not m/a)
@joseph2073
@joseph2073 2 года назад
@Harsh 🤣
@hxdx6950
@hxdx6950 2 года назад
or F = Mg
@gillesphilippedeboissay109
@gillesphilippedeboissay109 2 года назад
@@hxdx6950 no it's true en Earth only sometimes
@Mickymauserius
@Mickymauserius Год назад
But why does "self.x_vel += total_fx / self.mass * self.TIMESTEP" work. Shouldnt it be "self.x_vel += self.mass / total_fx * self.TIMESTEP"?
@rohan9739
@rohan9739 Год назад
@@Mickymauserius The formula is F = m * a, so a = F / m ; therefore self.x_vel += total_fx / self.mass * self.TIMESTEP works
@matheotrouille9085
@matheotrouille9085 2 года назад
Physics modeling is so interesting, look forward to see more like this !
@hyphenbruh7376
@hyphenbruh7376 2 года назад
That was awesome! I love and appreciate how you explained the logic behind each line of code and the concepts behind the physics of the orbits :D
@renegadezed
@renegadezed 2 года назад
f = ma .. NOT f = m/a .. force equals mass multiplied by acceleration
@TechWithTim
@TechWithTim 2 года назад
Great catch! Big brain fart from me
@renegadezed
@renegadezed 2 года назад
@@TechWithTim no big deal! you still promote Kyte? that auto complete coding help thing?
@Mohd_Zaid_khan
@Mohd_Zaid_khan Год назад
Funny thing is f ≠ ma, rather it's always dp/dt where p is linear momentum. for mass rate = 0, you can say net force along a line = mass multiplied by acceleration along that line
@jackyisking
@jackyisking 5 месяцев назад
But is gravity a force at all?
@youber3200
@youber3200 5 месяцев назад
​@jackyisking gravity is a field and gravitational force is a force :>
@kevinbacon8716
@kevinbacon8716 2 года назад
You’re about to hit a million subs. Congrats man. Your videos are great and as someone that’s new to python
@emirhanu8655
@emirhanu8655 2 года назад
You are awesome, bro. Every time producing different ideas.. Keep going Tim
@Heisenberg_99101
@Heisenberg_99101 2 года назад
This is just pure level genius, great help for a python project. Loving it 🙌
@DevilisshDan
@DevilisshDan 2 года назад
I think it's important to mention that what you're doing is just an approximate solution. When using the acceleration from the force and multiplying it with the timestep, you're taking a shortcut and calculating the average speed over a timestep. Since it's a many body problem, you can't get an "exact" solution.
@arkie87
@arkie87 2 года назад
yeah, it is also not energy conserving, as demonstrated when running without a vertical velocity component-- the planets just approached the sun and launched off to infinity.
@felicytatomaszewska2934
@felicytatomaszewska2934 2 года назад
We really look forward to your "exact solution"
@exar6765
@exar6765 2 года назад
@@felicytatomaszewska2934 He literally said : "You CAN'T get an exact solution". He's not saying it's a bad simulation, just an approximation
@mastershooter64
@mastershooter64 2 года назад
@@felicytatomaszewska2934 I think you can mathematically prove that it's impossible to get an analytic solution for a n-body problem
@aurelia8028
@aurelia8028 2 года назад
There's literally no other way to do it. I don't get what you mean by "shortcut". This method is forward euler integration, but yes there are more complex integration schemes like runge-kutta or verlet integration, but I don't think he knows anything about that
@amaarquadri
@amaarquadri 2 года назад
Nice tutorial! The x and y variables are shadowing each other at you suspected at the end. The reason that it doesn't break the program is because x and y ended up being the last values in the orbit array, which happens to be the same.
@danadasachan7208
@danadasachan7208 Год назад
Thank Tim. I really enjoyed this project. I remember studying these planetary equations when I was in my undergraduate mechanical engineering program back in 1985 and I remember coding the orbit of a planet in Turbo Pascal. Crazy.
@devbites77
@devbites77 2 года назад
Great! A fascinating simulation. I would love to see some more physics simulations using forces.
@xdaniels13
@xdaniels13 2 года назад
Awesome project Tim. I love physics and astronomy this is the perfect project to increase my skills in python :)
@_xiliam_7708
@_xiliam_7708 5 месяцев назад
If u love physics how u didn't notice f= m/a? I don't even mean that his planets make rotation around the sun in 1 sec while timestep is only 1 day?
@phase0400
@phase0400 Год назад
I would really enjoy seeing a 3D version of this. Nice video.
@NickHanson
@NickHanson 5 месяцев назад
This was a great introduction to the pygame library with a helpful foray into authentic simulation. Thank you for putting this together!
@NishantCosmos
@NishantCosmos 2 года назад
there's a great guy, explains the science behind planets in simplest way, claims we're confused like NO PROBLEM.
@googldeed
@googldeed 2 года назад
I can finally get into data simulation now that you made the perfect introduction for me.
@nadeeshani
@nadeeshani Год назад
You are amazing, Tim! Thank you so much for this project and for the way you explained it.
@universodacomputacao
@universodacomputacao Год назад
This is so awesome that made me understand more about Space Engine, the best Universe Simulator that I've ever seen. Thank you so much
@danielkursitis9031
@danielkursitis9031 2 года назад
Really enjoy this type of content, keep it up
@lupamo_Arnold
@lupamo_Arnold 2 года назад
Loved this project. Thanks Tim
@PayneMaximus
@PayneMaximus 11 месяцев назад
A more realistic simulation would be somewhat more complex than what you've done, since it would depend on the relative positions of each body and their velocities in a single instant, so you can use it as a starting point for the calculations. Still, good job! 😊
@annajuliagiza5916
@annajuliagiza5916 6 месяцев назад
Thank you for the wonderful tutorial. You do an excellent job of showing and explaining each of the steps, what you're using in Python, and what each part of the program does. I just completed the CS50 Intro to Python course and was looking for a project to practice the skills taught. I have an avid interest in space so coming across this tutorial was excellent.
@_xiliam_7708
@_xiliam_7708 5 месяцев назад
He did mistakes, but the idea and basic explanation is very good for the project
@domingezu4687
@domingezu4687 2 года назад
Very nice video TIM!
@reubenthomas1033
@reubenthomas1033 2 года назад
Awesome! Please do more of these!
@Sk8erMorris
@Sk8erMorris 2 года назад
ok this is sick, thanks for this one !
@bobmorone461
@bobmorone461 11 месяцев назад
Five Star! Excellent. Thank you for providing detailed explanations as you are introducing the code. Simulations like this offer a good way to learn and provide a platform upon which to build more interesting simulations.
@martin-xq7te
@martin-xq7te 2 года назад
Great tutorial Tim. Thankyou
@yudianimations
@yudianimations Год назад
great tutorial! thanks tim :D this also made me understand classes and stuff
@flashypepo
@flashypepo 3 месяца назад
Thanks, Tim. It is a very nice tutorial and introduction to astronomy, physics and Python, despite some minor flaws. I've made it, add the name of planet/sun to it and re-factored it in classes PlanetSimulation and Planet (which goes beyond your tutorial). It gave me a nice step up to go further in astronomy and astrophysics (when I was as young as you, I studied astronomy, years ago). kind regards, Peter.
@Ansh-Adonis
@Ansh-Adonis 4 месяца назад
ill take this a step and a half further, thank you!
@J_GB
@J_GB 2 года назад
this was awesome! very cool idea for a simulation
@wowgodz-5349
@wowgodz-5349 2 года назад
ngl i've been waiting for this
@DoctorSoulis
@DoctorSoulis 2 года назад
Ty for the hard work. I learned a lot from this tutorial! :D
@shubhaggarwall
@shubhaggarwall 2 года назад
well the thumbnail helped me revising the force formula thanksss
@toul100
@toul100 2 года назад
YOUR OPINION IS VALUED I LOVE THIS
@Greatbob-qu2ip
@Greatbob-qu2ip 6 месяцев назад
Coming from a physicist your explanation is by no means perfect but it's good enough for what you want to accomplish and that's more than enough keep up the good work
@Stl71
@Stl71 2 года назад
No surprise you have so many subscribers. Lots of interesting stuff in that channel, although I am not a python guy.
@muhammadmz8791
@muhammadmz8791 Год назад
thank you tim 🙏
@quyennguyen6725
@quyennguyen6725 2 года назад
Honestly, I love videos like this. this is a 2d model, can you upgrade it to a 3d model. I look forward to it. Thank you for your contribution to the community.
@efschannel3043
@efschannel3043 2 года назад
Omg I was thinking about this for a long time
@risveyhasan8931
@risveyhasan8931 2 года назад
Great work man.
@jdefar3243
@jdefar3243 2 года назад
love you'r videos :D they are great I learn so much
@philosopherPsy
@philosopherPsy 7 месяцев назад
While watching your lecture, I immediately entered the code and tried it out on my computer. It is perfect and beautiful. You have been a great inspiration to me. I will also try Earth's satellite, the Moon, the asteroid belt and other large outer planets. It was a really fun weekend. Thank you!!!!
@satyadev2011
@satyadev2011 7 месяцев назад
Great tut man.
@gidartsproduction5439
@gidartsproduction5439 2 года назад
Wow, high quality information...
@chrisdanny5180
@chrisdanny5180 2 года назад
This is a brilliant idea
@ConsultingjoeOnline
@ConsultingjoeOnline 2 года назад
Amazing video. Freaking sweet!
@marcrindermann9482
@marcrindermann9482 2 года назад
when you want to express 1 AU in metres, just increase the exponent by 3: 1 AU = 149.6e9 metres; rather than 149.6e6 km × 1000 m/km
@Felix-wo7qz
@Felix-wo7qz 2 года назад
cool tutorial, has been fun to program it!
@user-yt6of5mt4c
@user-yt6of5mt4c Год назад
amazing, you're really a genius
@malibaturhan
@malibaturhan 11 месяцев назад
it was really satisfying even by copying you step by step, thank you
@GordonFreeman69
@GordonFreeman69 Год назад
Thanks for the tutorial.
@tusharpatel2003
@tusharpatel2003 2 года назад
It's amazing 😀🤩 bro Thank you for this ❤️
@Burdiga_memes
@Burdiga_memes 2 года назад
I really enjoyed the tutorial I am 12 years coder and I understood very thing eaisly thanks to you
@vfx7t
@vfx7t 2 года назад
Good job ! And thanks from Algeria !
@jessysavard2133
@jessysavard2133 2 года назад
your vid help me a lot no matter if some shit false, that give us something to fix and keep going lil watch and like every vid !
@MilkenGamer42
@MilkenGamer42 2 года назад
This was a really fun tutorial to follow! I just started to learn Python and I found this video very informative. My problem with my code is that even though I was following this video, for some reason no matter what resolution I set the window, it would only do full screen and now windowed, so I'd have to hit window then X to close the program. You did an excellent job explaining how everything worked 😊
@itz_ronatime7527
@itz_ronatime7527 2 года назад
did u find a fix? my python doesnt run in windowed mode and its annoying..
@antoine2571
@antoine2571 2 года назад
that's amazing, thank you
@josephrios4437
@josephrios4437 2 года назад
awesome tutorial 👍
@timbeard8457
@timbeard8457 2 года назад
Super project! Have just bookmarked it for reference. Excellent that you included the interplanetary gravity too (from a coding and physics perspective). I agree that it was probably best not to use the general relativity description of gravity. The maths would have been hell! Newtonian physics was also good enough to get to the moon (I think) Questions: - Is there a way to only refresh / move just the changed items and not redraw everything? If there were lots of static objects, wouldn't that have a big performance impact? It would also mean that the complete history of the orbits wouldn't need redrawing each time, just the last point. - How would you approach having multiple sections in the app? Example: the canvas WIN on the left and some kind of control panel on the right for user input, plus a title / description area above both. - Would it be possible with pygame to dynamically change the window size, e.g. by the user grabbing the corner of the window? Please point me to any other videos or projects on GitHub you've done that address any of the points above.
@RAMESHNEUPANE-jg2uu
@RAMESHNEUPANE-jg2uu 2 месяца назад
Great. Thank you.
@feelsadgeman
@feelsadgeman 2 года назад
I had the same idea, i was going to make this on my final project
@GregoryCarnegie
@GregoryCarnegie 2 года назад
I played around with this and realised a slight simplification you can make. Since all objects feel the same acceleration regardless of their mass, you can write this script in terms of acceleration rather than force. e.g. velocity self.x_vel += total_ax * self.TIME_STEP
@aurelia8028
@aurelia8028 2 года назад
Yup using force is a rather "naive" way of doing it. division is also expensive for computers, so by calculating the acceleration directly, you can save the computer from doing quite a lot of unecessary work.
@AstroBene
@AstroBene 2 года назад
*sees the title, screams:* HELL YESS! Thanks!
@jdefar3243
@jdefar3243 2 года назад
fortunately i knew the math before hand otherwise this would be a lot harder ;D greate video
@unknownman5296
@unknownman5296 2 года назад
Thanks for the math lesson 👍
@si8915
@si8915 2 года назад
some day, tim will do "Filosophically Functional Life Forms In Python - Tutorial"
@rverm1000
@rverm1000 2 года назад
wow that was good and hard. thanks!
@ykslooper
@ykslooper 2 года назад
i love you so much tim your videos are amazing. I hope you clsoe time you will 1 millon subs
@norb3695
@norb3695 2 года назад
Hell yeah another Python tutorial 😃
@imen9464
@imen9464 2 года назад
Thanks a lot
@spaceflight
@spaceflight 2 года назад
very cool
@senaysew8231
@senaysew8231 2 года назад
It is really interesting!
@saranyaghosh2003
@saranyaghosh2003 2 года назад
The title just drew me in!
@bvg129
@bvg129 2 года назад
You can use strings for common colors in pygame now. Since 2.0
@leonellg3167
@leonellg3167 3 месяца назад
The way the logic of the orbits is implemented means the orbit (and updated_points) lists will keep growing without end if the simulation is kept running. A slight modification to add a max number of points, and then an if statement to remove older points once the list has reached this max number would mean the simulation can run forever without issues.
@absar_ahmad
@absar_ahmad 2 года назад
This man have magical powers to know what we are thinking, believe me.
@alexandermardis8179
@alexandermardis8179 2 года назад
Awesome ty!
@lp2045
@lp2045 2 года назад
Now let's see uranus' simulation lol Great vid btw
@Totema.
@Totema. 2 года назад
This is so nice 😮
@lissankoirala
@lissankoirala 2 года назад
45:00 - you made an error here, F = m / a [supposed to be F = m*a]
@EarlWallaceNYC
@EarlWallaceNYC 2 года назад
Thanks for the fun video. I was impressed that you included the planet-planet interactions. I wonder how long you can run this before the small errors kill it?
@Anonymous-8080
@Anonymous-8080 2 года назад
It will collapse in 49 years 56 days
@petruthegamer9777
@petruthegamer9777 2 года назад
Thanks.
@jakovbilic4556
@jakovbilic4556 2 года назад
Superb!
@ayushmaanyadav4069
@ayushmaanyadav4069 2 года назад
I have my exams rn, i am gonna make this some day, probably gonna add a feature to see the simulation of objects around the planet, and also a feature to add an object in this system, like any object of a given mass, moving with a particular velocity in some direction. Gonna be difficult but can be done
@fun-damentals6354
@fun-damentals6354 6 месяцев назад
this was a really informational video. to all new programmers, let me teach a way to partially escape tutorial hell. if you want to learn a language, but dont wanna worry about the logistics of a project, follow along with a tutorial in another language. i am learning c++, and it is about as far from python as it gets, and it helped me learn the language while still following along with the video
@cs_armenglish
@cs_armenglish 5 месяцев назад
Fantastic
@frankhaug1517
@frankhaug1517 Год назад
15 minutes in. great video so far, i just hit all the buttons. however, you can do AU = 149.6e9 instead, same effect. edit: and since you mentioned consistency: 1*10**X = 1eX
@StarboyWithTech
@StarboyWithTech 2 года назад
Really unexpected project like every Time 😉.
@techzenik
@techzenik 2 года назад
Awesome!!!
@navpreetkaur5827
@navpreetkaur5827 2 года назад
Thanks I enjoyed the whole video!
@TechWithTim
@TechWithTim 2 года назад
Glad you enjoyed it!
@ANNGUYEN-cw7lw
@ANNGUYEN-cw7lw 9 месяцев назад
Your tutorial is very awesome. I hope you will create many other tutorial in the future ?.
@TechWithTim
@TechWithTim 9 месяцев назад
That's the plan!
@dymonn
@dymonn 2 года назад
bro u a alien, damnn👽
2 года назад
Nice!
@taradavies3073
@taradavies3073 2 года назад
Tim, great video but the physics was a little off. You can’t take that force into components to find the velocity. The gravitational force acts as a centripetal force such that GmM/r^2 = v^2/r * m (F = ma) Also, the distance should be from radius to the other radius so we should have added this.radius + other.radius
@fredericoamigo
@fredericoamigo 2 года назад
awesome!
@artyom9149
@artyom9149 2 года назад
Amazing
@lamedev1342
@lamedev1342 2 года назад
Added a few new features to top off this project! I connected to a space api that displays people in space rn and also their names. Along with this users can watch planets move in slow mo.
@rameshk9462
@rameshk9462 2 года назад
where can i see that
Далее
Coding Adventure: Ant and Slime Simulations
17:54
Просмотров 1,8 млн
Make Pong With Python!
1:12:42
Просмотров 112 тыс.
LISA - ROCKSTAR (MV Teaser)
00:10
Просмотров 10 млн
Coding Adventure: Solar System
12:12
Просмотров 842 тыс.
10 FORBIDDEN Sorting Algorithms
9:41
Просмотров 799 тыс.
5 Good Python Habits
17:35
Просмотров 397 тыс.
Falling Into Jupiter (Simulation)
5:04
Просмотров 2,3 млн
Coding Adventure: Simulating Fluids
47:52
Просмотров 1,6 млн
how NASA writes space-proof code
6:03
Просмотров 2,1 млн
Coding Challenge 180: Falling Sand
23:00
Просмотров 790 тыс.
Simulating Rocket Trajectories with Python
16:36
Просмотров 10 тыс.
25 nooby Python habits you need to ditch
9:12
Просмотров 1,7 млн