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 👍
@randomdude73862 жыл бұрын
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
@HypnosisBear2 жыл бұрын
The thumbnail is click bait.😑 I thought you are gonna make a 3D simulation.
@mr.whiteboard63572 жыл бұрын
@@HypnosisBear Yeah me too
@Hiyouri0052 жыл бұрын
HEY CAN YOU POST CODE TOO//
@rafigasparyan65842 жыл бұрын
@@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).
@lissankoirala2 жыл бұрын
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!
@harshmirdhwal2 жыл бұрын
It's called manifestation bro
@heelercs2 жыл бұрын
@@harshmirdhwal Lol, sure bro
@ryanchowdhary9652 жыл бұрын
Ai maybe??
@harshmirdhwal2 жыл бұрын
@@ryanchowdhary965 force greater than ai
@speedybenzedrex67862 жыл бұрын
tim hacked u and used alll your data to create the perfect video for you
@vishsinghania2 жыл бұрын
amazing tutorial 👍 just a correction at 45:00 F = m times a (not m/a)
@joseph20732 жыл бұрын
@Harsh 🤣
@hxdx69502 жыл бұрын
or F = Mg
@gillesphilippedeboissay1092 жыл бұрын
@@hxdx6950 no it's true en Earth only sometimes
@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 Жыл бұрын
@@Mickymauserius The formula is F = m * a, so a = F / m ; therefore self.x_vel += total_fx / self.mass * self.TIMESTEP works
@matheotrouille90852 жыл бұрын
Physics modeling is so interesting, look forward to see more like this !
@DevilisshDan2 жыл бұрын
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.
@arkie872 жыл бұрын
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.
@felicytatomaszewska2 жыл бұрын
We really look forward to your "exact solution"
@exar67652 жыл бұрын
@@felicytatomaszewska He literally said : "You CAN'T get an exact solution". He's not saying it's a bad simulation, just an approximation
@mastershooter642 жыл бұрын
@@felicytatomaszewska I think you can mathematically prove that it's impossible to get an analytic solution for a n-body problem
@aurelia80282 жыл бұрын
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
@hyphenbruh73762 жыл бұрын
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
@renegadezed2 жыл бұрын
f = ma .. NOT f = m/a .. force equals mass multiplied by acceleration
@TechWithTim2 жыл бұрын
Great catch! Big brain fart from me
@renegadezed2 жыл бұрын
@@TechWithTim no big deal! you still promote Kyte? that auto complete coding help thing?
@Mohd_Zaid_khan2 жыл бұрын
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 Жыл бұрын
But is gravity a force at all?
@youber3200 Жыл бұрын
@jackyisking gravity is a field and gravitational force is a force :>
@NishantCosmos2 жыл бұрын
there's a great guy, explains the science behind planets in simplest way, claims we're confused like NO PROBLEM.
@kevinbacon87162 жыл бұрын
You’re about to hit a million subs. Congrats man. Your videos are great and as someone that’s new to python
@xdaniels132 жыл бұрын
Awesome project Tim. I love physics and astronomy this is the perfect project to increase my skills in python :)
@_xiliam_770811 ай бұрын
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?
@Heisenberg_991012 жыл бұрын
This is just pure level genius, great help for a python project. Loving it 🙌
@annajuliagiza5916 Жыл бұрын
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_770811 ай бұрын
He did mistakes, but the idea and basic explanation is very good for the project
@emirhanu86552 жыл бұрын
You are awesome, bro. Every time producing different ideas.. Keep going Tim
@amaarquadri2 жыл бұрын
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.
@fun-damentals6354 Жыл бұрын
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
@PayneMaximus Жыл бұрын
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! 😊
@Greatbob-qu2ip Жыл бұрын
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
@phase04002 жыл бұрын
I would really enjoy seeing a 3D version of this. Nice video.
@NickHanson11 ай бұрын
This was a great introduction to the pygame library with a helpful foray into authentic simulation. Thank you for putting this together!
@flashypepo9 ай бұрын
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.
@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
@philosopherPsy Жыл бұрын
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!!!!
@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.
@lissankoirala2 жыл бұрын
45:00 - you made an error here, F = m / a [supposed to be F = m*a]
@Stl712 жыл бұрын
No surprise you have so many subscribers. Lots of interesting stuff in that channel, although I am not a python guy.
@danielkursitis90312 жыл бұрын
Really enjoy this type of content, keep it up
@bobmorone461 Жыл бұрын
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.
@marcrindermann94822 жыл бұрын
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
@nadeeshani Жыл бұрын
You are amazing, Tim! Thank you so much for this project and for the way you explained it.
@quyennguyen67252 жыл бұрын
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.
@domingezu46872 жыл бұрын
Very nice video TIM!
@googldeed2 жыл бұрын
I can finally get into data simulation now that you made the perfect introduction for me.
@devbites772 жыл бұрын
Great! A fascinating simulation. I would love to see some more physics simulations using forces.
@GregoryCarnegie2 жыл бұрын
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
@aurelia80282 жыл бұрын
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.
@timbeard84572 жыл бұрын
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.
@Burdiga_memes2 жыл бұрын
I really enjoyed the tutorial I am 12 years coder and I understood very thing eaisly thanks to you
@AstroBene2 жыл бұрын
*sees the title, screams:* HELL YESS! Thanks!
@Sk8erMorris2 жыл бұрын
ok this is sick, thanks for this one !
@wowgodz-53492 жыл бұрын
ngl i've been waiting for this
@si89152 жыл бұрын
some day, tim will do "Filosophically Functional Life Forms In Python - Tutorial"
@shubhaggarwall2 жыл бұрын
well the thumbnail helped me revising the force formula thanksss
@toul1002 жыл бұрын
YOUR OPINION IS VALUED I LOVE THIS
@Ansh-Adonis11 ай бұрын
ill take this a step and a half further, thank you!
@LeonardRibeiro252 ай бұрын
Appreciate this being available !
@malibaturhan Жыл бұрын
it was really satisfying even by copying you step by step, thank you
@lupamo_Arnold2 жыл бұрын
Loved this project. Thanks Tim
@ddavid14142 жыл бұрын
fortunately i knew the math before hand otherwise this would be a lot harder ;D greate video
@vfx7t2 жыл бұрын
Good job ! And thanks from Algeria !
@jacobjohnson71255 ай бұрын
Thanks so much. I followed your tutorial and finally got it working. Funny thing was that I had the most minor errors in my copy (I was typing it in as I watched the video) and didn't get it fully working until the end and after I downloaded from the github then did a diff between that and what I'd typed. That was so weird that you could put in a y velocity only and then the update_position method would have the rest fall into place such that it maintained orbit.
@leonellg31679 ай бұрын
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.
@yudianimations2 жыл бұрын
great tutorial! thanks tim :D this also made me understand classes and stuff
@efschannel30432 жыл бұрын
Omg I was thinking about this for a long time
@absar_ahmad2 жыл бұрын
This man have magical powers to know what we are thinking, believe me.
@bvg1292 жыл бұрын
You can use strings for common colors in pygame now. Since 2.0
@NeonsStyleHD3 ай бұрын
Excellent video, I learned a lot. Subbed.
@趙重茂趙重茂2 жыл бұрын
amazing, you're really a genius
@reubenthomas10332 жыл бұрын
Awesome! Please do more of these!
@J_GB2 жыл бұрын
this was awesome! very cool idea for a simulation
@tobik2047 Жыл бұрын
hi, in min 6:15, why didnt you just do a while True-loop and if the user wanted to quit you just return or break out of the main-function/while-loop? just want to know why since im pretty new to python
@professor_ozzy2 жыл бұрын
Ty for the hard work. I learned a lot from this tutorial! :D
@jessysavard21332 жыл бұрын
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 !
@gidartsproduction54392 жыл бұрын
Wow, high quality information...
@TAP7a2 жыл бұрын
Skip involving trigonometry, do it all component by component! Force_x = (other.x - self.x) * Planet.G * self.mass * other.mass / distance ** 3 Force_y = (other.y - self.y) * Planet.G * self.mass * other.mass / distance ** 3 No need for expensive atan calcs, just needs another 2 factors to multiply! Also would recommend either Verlet or RK-4 integration schemes rather than Euler ;)
@lp20452 жыл бұрын
Now let's see uranus' simulation lol Great vid btw
@martin-xq7te2 жыл бұрын
Great tutorial Tim. Thankyou
@ykslooper2 жыл бұрын
i love you so much tim your videos are amazing. I hope you clsoe time you will 1 millon subs
@feelsadgeman2 жыл бұрын
I had the same idea, i was going to make this on my final project
@MilkenGamer422 жыл бұрын
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_ronatime75272 жыл бұрын
did u find a fix? my python doesnt run in windowed mode and its annoying..
@ddavid14142 жыл бұрын
love you'r videos :D they are great I learn so much
@novidtoshow8 ай бұрын
Just a little nit: the gravitational force weakens as the inverse square of the distance. It doesn't weaken "exponentially". The word, "exponentially", has a very specific mathematical meaning. You're gonna want to have that meaning available to you one day when you really need it.
@Felix-wo7qz2 жыл бұрын
cool tutorial, has been fun to program it!
@ayushmaanyadav40692 жыл бұрын
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
@ConsultingjoeOnline2 жыл бұрын
Amazing video. Freaking sweet!
@frankhaug15172 жыл бұрын
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
@trevorelvis13552 жыл бұрын
MY HEART LITERALLY SKIPPED A BEAT WHEN I SAW THIS VIDEO. I WAS SOOOOOOO EXCITED. KEEP 'EM COMING
@muhammadmz87912 жыл бұрын
thank you tim 🙏
@raymondmichael49872 жыл бұрын
Thanks for this Tim, consider a 3D version of this too. Also as someone mentioned, relax you’re doing such a wonderful and we appreciate it Greetings from Tanzania 🇹🇿
@tusharpatel20032 жыл бұрын
It's amazing 😀🤩 bro Thank you for this ❤️
@paaritoshjain2 жыл бұрын
please do a rocket simulation too!!!
@Andbovi Жыл бұрын
I understood the force vector better in this video than in physics class... Although who knows, maybe I'm just smarter now and more interested in more things.
@satyadev2011 Жыл бұрын
Great tut man.
@risveyhasan89312 жыл бұрын
Great work man.
@chrisdanny51802 жыл бұрын
This is a brilliant idea
@hovardlee2 жыл бұрын
Nice really :) My comments: 1. Formula should be F = m * a not F = m / a 2. There was a nice place for a list comprehension with updated_points 3. When you adding a point to self.orbit isn't it growing infinitely? If you run it for a couple of seconds it should be fine. But if you run it for a couple of hours wouldn't it slow down ?
@fjoralbismolli34902 жыл бұрын
I guess one possible solution to your third comment would be to round the points you append to self.orbit, and do not append if the pair is in the list. However, checking existence in a list is O(n), so you would better use a set. Beware, set() is not ordered, so you might want to use an ordered set instead.
@Birsic982 жыл бұрын
@@fjoralbismolli3490 Smooth
@GordonFreeman69 Жыл бұрын
Thanks for the tutorial.
@ANNGUYEN-cw7lw Жыл бұрын
Your tutorial is very awesome. I hope you will create many other tutorial in the future ?.
@TechWithTim Жыл бұрын
That's the plan!
@DSCuber-28-01-20192 жыл бұрын
Hey Tim, how can we add the Moon to this simulation, can we do the exact same thing we did to the planets but centering from not the sun but earth?
@Djellowman2 жыл бұрын
Yes, but it will be so close to the earth that you can't display it at this scale
@DSCuber-28-01-20192 жыл бұрын
@@Djellowman i tried to do it using real values but it just went through a straight line and out of the screen
@dirtboi87922 жыл бұрын
@@DSCuber-28-01-2019 Same :( if you figure it up tell me
@lamedev13422 жыл бұрын
@@DSCuber-28-01-2019 ya same
@xyy28612 жыл бұрын
I also added the moon but it was immediately catched by the sun and kicked out of the system. What's wrong here?
@tiagosolano9728 Жыл бұрын
Maybe someone already pointed this out, but the distance from the center of mass of the earth to astronauts in orbit IS NOT the reason why they do not experience the force of gravity. The reason is that they are on orbit around the earth, which is equivalent to being on free fall. Earth's gravitational field goes way beyond low earth orbit, as you can reason from the fact that the moon is in orbit around the earth at a far greater distance.
@carldavidson-desbiens1382 жыл бұрын
Hey, nice examples. try this. Make a ball of 24000 miles. Make water stick to it. To validate your code, use earth code calculator. At what distance should we stop beeing able to be able to see statue of liberty and replicate in your model. This will be the most challenging coding session you will ever create. Have fun.
@manisho76952 жыл бұрын
Tim is the best tutor out there for teaching coding
@dimahome544 Жыл бұрын
1. The problem is in the code - infinite growth of points in the "orbit" array 2. The initial distances of the planets must be taken from the apogee, and not the average. And accordingly, take the lowest initial speed (at apogee). Then you will get the correct ellipses. 3. Due to the quantum nature of calculations over time, an error accumulates in the momentum of the system of objects. The closer the objects are, the greater the error. It is necessary to check each step so that the total momentum of the two interacting bodies does not change after changing speeds.
@dymonn2 жыл бұрын
bro u a alien, damnn👽
@bidam224 Жыл бұрын
hey man I just realized that at 29:36 , you are using MS Whiteboard in Turkish. Are you trying to learn Turkish or maybe one of your parents moved to different country from Turkey?
@josephrios44372 жыл бұрын
awesome tutorial 👍
@gerrymarshall47842 жыл бұрын
the Sun also orbits the centre of mass of the solar system. A point known as a barycenter (there is one between any masses Earth-Moon). Whilst this may not seem significant I understand that this centre of mass can be up to 2MKm from the centre of the Sun. If the velocity of the sun is unknown I suppose you could start at zero.
@natyacodes2 жыл бұрын
guy teaches almost a million programmers, but doesn't know the difference between star and planet 😂😂 Nice Video! learned a lot of stuff
@playerscience2 жыл бұрын
That's because he is not a nerd LoL.
@mohammadshahbaz2962 жыл бұрын
Hello Tim, in your video you said that we could look at the math to understand why you chose the scale the way you did. However, the turtle code you took inspiration from did not explain this either. Could you please explain why 250/ AU maps to 100 pixels?
@alperkama67982 жыл бұрын
I think there is a mis explanation there. It should be 1 AU = 250px
@boseongcho622 жыл бұрын
I think so with alper kama
@The0070382 жыл бұрын
Resolving the attraction force into x and y components can more simply be done by using similar triangles (also doesn't require calls to the math library so I believe it wod be faster also) For 2 similar triangles with sides Fx, Fy, F and Distx, Disty and Dist have consistent ratios between similar side lengths You can say Fx / F = Distx / Dist As such Fx = Distx * F / Dist Simarly Fy = Disty * F / Dist A little neater and a little faster but equally as accurate :)
@ImNotActuallyChristian2 жыл бұрын
while simpler, i wonder if it actually is faster. Calculations done in python can be 100s of times slower than the C based libraries. I'll try go and do some benchmarks.
@The0070382 жыл бұрын
@@ImNotActuallyChristian I'm very interested to see how this turns out! I simply assumed since the implementation of sine requires some amount logic for bounds checking and range reduction as well as then generally computing a Taylor series and some correction. (as far as I understand from the c standard library as cpython simply implements many c math) Meanwhile the similar triangles method is 2 basic math operations.
@The0070382 жыл бұрын
@@ImNotActuallyChristian Hey mate. I was so curious I ran some tests myself. I ran both methods on 100,000 random sets of numbers Using the trig method took between 5.83 and 6.05s (depending on the run) While the triangle method took between 4.92 and 5.18s So the trig method is roughly 20% slower than the triangle method. The more you know!
@tiagosolano9728 Жыл бұрын
Alternatively you don't need to compute the square root of the distance, since what you really need to compute the force is the distance squared.
@lucidjuice101 Жыл бұрын
The reason why the value of y_vel of venus is negative is because of the fact that venus' orbit is titled to 180 degrees. So unlike all other planets, it orbits clockwise around the sun.
@PDsChannel0112 Жыл бұрын
The planets are not orbiting but after taking a little curve they just start moving straight what should I do?
@PDsChannel0112 Жыл бұрын
I checked the code from your code on github but after fixing some mistakes it was still not working what should I do?