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 👍
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
@@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).
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!
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
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.
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.
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
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
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! 😊
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
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.
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.
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.
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!!!!
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.
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.
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
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.
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 ;)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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 :)
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.
@@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.
@@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!
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.
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
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
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 ?
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.
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 😊
"Hence why when you go up in space, you have zero gravity" Unless you're talking about thought experiments where humans try to leave the solar system entirely, there's still tonnes of gravity around, it's what lets satellites orbit
I am interested in astronomy and know something about math and physics so I found your video very interesting. My only disappointment is that you couldn't fit all the 8 planets (and maybe Pluto) in the simulation without making the orbits of the inner planets very small and difficult to see (but that is a consequence of the limited size of our monitors). I remember the first astronomy program I had (called Planet Engine) was a simulation of planetary orbits. But it wasn't animated like yours; it was just a static display of the relative position of the planets at the time the program was run. It could display the positions of just the inner planets or all the planets, but of course in the latter case we have the problem of the inner planetary orbits being too small to see. The computer that ran Planet Engine is decades old and I doubt it has the speed necessary to show animated displays. Nor would it be capable of displaying the stars, galaxies, nebulae, etc. incorporated into modern astronomy apps.
Instead of planets you could just describe massive space objects. If they have the mass they'll have the orbits. After all, it's a human classification. To planets, stars and black holes, they only perceive lower and greater forces
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.
There is one thing that needs to be fixed. When drawing the orbit of the planet we are using all the coordinates that the planet has gone through. And the plant can go through the same coordinate as much as we let the program run. So this means that we are appending the same points over and over for each rotation around the sun for a given planet. This means that the tuple will get infinitely large if we keep running the program and it will slow everything down. A program like this might not have such problems because we won't run it that long. But if someone wants to expand on the idea of this program. They need to consider this thing. One way to fix it is to get the coordinates of the first point, and then when looping through the list of points you can check if you encounter the first point again. If you do then you can break the loop since the circle has already been fully drawn.
or you can decide to keep the last "MAX_ORBIT_POINTS" of points in the list, where MAX_ORBIT_POINTS = abs(math.ceil(2*4(a little more then PHI for approximation and to be sure to have enogh point)*"initial x"/("initial velocity"*TIMESTEP)). in this way you have enogh points to draw the entire last orbit (and a little more) and if you want, lowering MAX_ORBIT_POINTS putting an angle in radiants instead of 4, you can have a small trail after the planet based on the angle.
There is one small problem with the program, after a while the orbit list becomes so full of past positions of all the planets that it will slow down a lot. This can be fixed by putting this at the bottom of the update_position method in the planet class: if len(self.orbit) > ORBIT_LENGTH: self.orbit.pop(0) This will remove the first position saved in the list. To have one full circle for all planets at least ORBIT_LENGTH has to be 700, but something between 50 and 150 will produce a small line after it.
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 🇹🇿
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
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.
you say that the order between other.x and self.x in the formula for distance dosent matter. Actually, it does since we use these distances to compute the theta angle...
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 👍
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
The thumbnail is click bait.😑 I thought you are gonna make a 3D simulation.
@@HypnosisBear Yeah me too
HEY CAN YOU POST CODE TOO//
@@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).
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!
It's called manifestation bro
@@harshmirdhwal Lol, sure bro
Ai maybe??
@@ryanchowdhary965 force greater than ai
tim hacked u and used alll your data to create the perfect video for you
f = ma .. NOT f = m/a .. force equals mass multiplied by acceleration
Great catch! Big brain fart from me
@@TechWithTim no big deal! you still promote Kyte? that auto complete coding help thing?
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
But is gravity a force at all?
@jackyisking gravity is a field and gravitational force is a force :>
Physics modeling is so interesting, look forward to see more like this !
there's a great guy, explains the science behind planets in simplest way, claims we're confused
like NO PROBLEM.
amazing tutorial 👍
just a correction at 45:00
F = m times a (not m/a)
@Harsh 🤣
or F = Mg
@@hxdx6950 no it's true en Earth only sometimes
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"?
@@Mickymauserius The formula is F = m * a, so a = F / m ; therefore self.x_vel += total_fx / self.mass * self.TIMESTEP works
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.
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.
We really look forward to your "exact solution"
@@felicytatomaszewska He literally said : "You CAN'T get an exact solution". He's not saying it's a bad simulation, just an approximation
@@felicytatomaszewska I think you can mathematically prove that it's impossible to get an analytic solution for a n-body problem
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
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
This is just pure level genius, great help for a python project. Loving it 🙌
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! 😊
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
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
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.
You’re about to hit a million subs. Congrats man. Your videos are great and as someone that’s new to python
I would really enjoy seeing a 3D version of this.
Nice video.
Awesome project Tim. I love physics and astronomy this is the perfect project to increase my skills in python :)
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?
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
This was a great introduction to the pygame library with a helpful foray into authentic simulation. Thank you for putting this together!
You are awesome, bro. Every time producing different ideas.. Keep going Tim
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.
He did mistakes, but the idea and basic explanation is very good for the project
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.
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!!!!
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.
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.
I really enjoyed the tutorial I am 12 years coder and I understood very thing eaisly thanks to you
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
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.
I can finally get into data simulation now that you made the perfect introduction for me.
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
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 ;)
some day, tim will do "Filosophically Functional Life Forms In Python - Tutorial"
45:00 - you made an error here, F = m / a [supposed to be F = m*a]
No surprise you have so many subscribers. Lots of interesting stuff in that channel, although I am not a python guy.
You can use strings for common colors in pygame now. Since 2.0
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.
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.
Great! A fascinating simulation. I would love to see some more physics simulations using forces.
ngl i've been waiting for this
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.
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.
please do a rocket simulation too!!!
ill take this a step and a half further, thank you!
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.
YOUR OPINION IS VALUED I LOVE THIS
well the thumbnail helped me revising the force formula thanksss
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.
This man have magical powers to know what we are thinking, believe me.
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.
Really enjoy this type of content, keep it up
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.
You are amazing, Tim! Thank you so much for this project and for the way you explained it.
Very nice video TIM!
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.
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 :)
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.
@@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.
@@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!
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.
fortunately i knew the math before hand otherwise this would be a lot harder ;D greate video
I had the same idea, i was going to make this on my final project
ok this is sick, thanks for this one !
*sees the title, screams:* HELL YESS!
Thanks!
it was really satisfying even by copying you step by step, thank you
MY HEART LITERALLY SKIPPED A BEAT WHEN I SAW THIS VIDEO. I WAS SOOOOOOO EXCITED. KEEP 'EM COMING
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.
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
Appreciate this being available !
guy teaches almost a million programmers, but doesn't know the difference between star and planet 😂😂
Nice Video! learned a lot of stuff
That's because he is not a nerd LoL.
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
Now let's see uranus' simulation lol
Great vid btw
great tutorial! thanks tim :D
this also made me understand classes and stuff
:. F = mv²/r in circular motion.. So you can actually find the velocity of an object.
Hence - v = √(rF/m) 😊
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 ?
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.
@@fjoralbismolli3490 Smooth
Omg I was thinking about this for a long time
thank you tim 🙏
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 😊
did u find a fix? my python doesnt run in windowed mode and its annoying..
Excellent video, I learned a lot. Subbed.
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 !
"Hence why when you go up in space, you have zero gravity"
Unless you're talking about thought experiments where humans try to leave the solar system entirely, there's still tonnes of gravity around, it's what lets satellites orbit
I am interested in astronomy and know something about math and physics so I found your video very interesting. My only disappointment is that you couldn't fit all the 8 planets (and maybe Pluto) in the simulation without making the orbits of the inner planets very small and difficult to see (but that is a consequence of the limited size of our monitors). I remember the first astronomy program I had (called Planet Engine) was a simulation of planetary orbits. But it wasn't animated like yours; it was just a static display of the relative position of the planets at the time the program was run. It could display the positions of just the inner planets or all the planets, but of course in the latter case we have the problem of the inner planetary orbits being too small to see. The computer that ran Planet Engine is decades old and I doubt it has the speed necessary to show animated displays. Nor would it be capable of displaying the stars, galaxies, nebulae, etc. incorporated into modern astronomy apps.
Instead of planets you could just describe massive space objects. If they have the mass they'll have the orbits. After all, it's a human classification. To planets, stars and black holes, they only perceive lower and greater forces
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.
Good job ! And thanks from Algeria !
amazing, you're really a genius
i love you so much tim your videos are amazing. I hope you clsoe time you will 1 millon subs
The title just drew me in!
Awesome! Please do more of these!
There is one thing that needs to be fixed. When drawing the orbit of the planet we are using all the coordinates that the planet has gone through. And the plant can go through the same coordinate as much as we let the program run. So this means that we are appending the same points over and over for each rotation around the sun for a given planet. This means that the tuple will get infinitely large if we keep running the program and it will slow everything down. A program like this might not have such problems because we won't run it that long. But if someone wants to expand on the idea of this program. They need to consider this thing. One way to fix it is to get the coordinates of the first point, and then when looping through the list of points you can check if you encounter the first point again. If you do then you can break the loop since the circle has already been fully drawn.
or you can decide to keep the last "MAX_ORBIT_POINTS" of points in the list, where MAX_ORBIT_POINTS = abs(math.ceil(2*4(a little more then PHI for approximation and to be sure to have enogh point)*"initial x"/("initial velocity"*TIMESTEP)). in this way you have enogh points to draw the entire last orbit (and a little more) and if you want, lowering MAX_ORBIT_POINTS putting an angle in radiants instead of 4, you can have a small trail after the planet based on the angle.
Tim is the best tutor out there for teaching coding
You should try commenting as you go to make what youre doing more clear
There is one small problem with the program, after a while the orbit list becomes so full of past positions of all the planets that it will slow down a lot. This can be fixed by putting this at the bottom of the update_position method in the planet class:
if len(self.orbit) > ORBIT_LENGTH: self.orbit.pop(0)
This will remove the first position saved in the list. To have one full circle for all planets at least ORBIT_LENGTH has to be 700, but something between 50 and 150 will produce a small line after it.
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 🇹🇿
Wow, high quality information...
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
Ty for the hard work. I learned a lot from this tutorial! :D
this was awesome! very cool idea for a simulation
Loved this project. Thanks Tim
Really appreciate you turning your facecam off while talking about stuff that's behind your facecam. It's the little things.
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.
where can i see that
you say that the order between other.x and self.x in the formula for distance dosent matter. Actually, it does since we use these distances to compute the theta angle...
Great tutorial Tim. Thankyou
cool tutorial, has been fun to program it!
This is a brilliant idea
love you'r videos :D they are great I learn so much
It's amazing 😀🤩 bro
Thank you for this ❤️