Planet Simulation In Python - Tutorial

Поділитися
Вставка
  • Опубліковано 27 лис 2024

КОМЕНТАРІ • 448

  • @TechWithTim
    @TechWithTim  2 роки тому +153

    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 роки тому +18

      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 роки тому +5

      The thumbnail is click bait.😑 I thought you are gonna make a 3D simulation.

    • @mr.whiteboard6357
      @mr.whiteboard6357 2 роки тому +1

      @@HypnosisBear Yeah me too

    • @Hiyouri005
      @Hiyouri005 2 роки тому +1

      HEY CAN YOU POST CODE TOO//

    • @rafigasparyan6584
      @rafigasparyan6584 2 роки тому +1

      @@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 роки тому +260

    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 роки тому +6

      It's called manifestation bro

    • @heelercs
      @heelercs 2 роки тому +4

      @@harshmirdhwal Lol, sure bro

    • @ryanchowdhary965
      @ryanchowdhary965 2 роки тому +1

      Ai maybe??

    • @harshmirdhwal
      @harshmirdhwal 2 роки тому

      @@ryanchowdhary965 force greater than ai

    • @speedybenzedrex6786
      @speedybenzedrex6786 2 роки тому +1

      tim hacked u and used alll your data to create the perfect video for you

  • @renegadezed
    @renegadezed 2 роки тому +152

    f = ma .. NOT f = m/a .. force equals mass multiplied by acceleration

    • @TechWithTim
      @TechWithTim  2 роки тому +70

      Great catch! Big brain fart from me

    • @renegadezed
      @renegadezed 2 роки тому +3

      @@TechWithTim no big deal! you still promote Kyte? that auto complete coding help thing?

    • @Mohd_Zaid_khan
      @Mohd_Zaid_khan 2 роки тому +16

      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 11 місяців тому +1

      But is gravity a force at all?

    • @youber3200
      @youber3200 10 місяців тому +1

      ​@jackyisking gravity is a field and gravitational force is a force :>

  • @matheotrouille9085
    @matheotrouille9085 2 роки тому +32

    Physics modeling is so interesting, look forward to see more like this !

  • @NishantCosmos
    @NishantCosmos 2 роки тому +2

    there's a great guy, explains the science behind planets in simplest way, claims we're confused
    like NO PROBLEM.

  • @vishsinghania
    @vishsinghania 2 роки тому +173

    amazing tutorial 👍
    just a correction at 45:00
    F = m times a (not m/a)

    • @joseph2073
      @joseph2073 2 роки тому +3

      @Harsh 🤣

    • @hxdx6950
      @hxdx6950 2 роки тому +1

      or F = Mg

    • @gillesphilippedeboissay109
      @gillesphilippedeboissay109 2 роки тому +5

      @@hxdx6950 no it's true en Earth only sometimes

    • @Mickymauserius
      @Mickymauserius Рік тому +1

      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 Рік тому +2

      @@Mickymauserius The formula is F = m * a, so a = F / m ; therefore self.x_vel += total_fx / self.mass * self.TIMESTEP works

  • @DevilisshDan
    @DevilisshDan 2 роки тому +68

    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 роки тому +10

      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.

    • @felicytatomaszewska
      @felicytatomaszewska 2 роки тому +2

      We really look forward to your "exact solution"

    • @exar6765
      @exar6765 2 роки тому +24

      @@felicytatomaszewska 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 роки тому +4

      @@felicytatomaszewska I think you can mathematically prove that it's impossible to get an analytic solution for a n-body problem

    • @aurelia8028
      @aurelia8028 2 роки тому +3

      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

  • @Greatbob-qu2ip
    @Greatbob-qu2ip 11 місяців тому

    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

  • @Heisenberg_99101
    @Heisenberg_99101 2 роки тому +37

    This is just pure level genius, great help for a python project. Loving it 🙌

  • @PayneMaximus
    @PayneMaximus Рік тому +16

    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! 😊

  • @fun-damentals6354
    @fun-damentals6354 11 місяців тому +4

    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

  • @hyphenbruh7376
    @hyphenbruh7376 2 роки тому +7

    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

  • @amaarquadri
    @amaarquadri 2 роки тому +7

    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.

  • @kevinbacon8716
    @kevinbacon8716 2 роки тому +3

    You’re about to hit a million subs. Congrats man. Your videos are great and as someone that’s new to python

  • @phase0400
    @phase0400 2 роки тому +5

    I would really enjoy seeing a 3D version of this.
    Nice video.

  • @xdaniels13
    @xdaniels13 2 роки тому +8

    Awesome project Tim. I love physics and astronomy this is the perfect project to increase my skills in python :)

    • @_xiliam_7708
      @_xiliam_7708 10 місяців тому

      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?

  • @marcrindermann9482
    @marcrindermann9482 2 роки тому +8

    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

  • @NickHanson
    @NickHanson 10 місяців тому

    This was a great introduction to the pygame library with a helpful foray into authentic simulation. Thank you for putting this together!

  • @emirhanu8655
    @emirhanu8655 2 роки тому +4

    You are awesome, bro. Every time producing different ideas.. Keep going Tim

  • @annajuliagiza5916
    @annajuliagiza5916 11 місяців тому +1

    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 10 місяців тому

      He did mistakes, but the idea and basic explanation is very good for the project

  • @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.

  • @philosopherPsy
    @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!!!!

  • @flashypepo
    @flashypepo 8 місяців тому

    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.

  • @quyennguyen6725
    @quyennguyen6725 2 роки тому +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.

  • @Burdiga_memes
    @Burdiga_memes 2 роки тому

    I really enjoyed the tutorial I am 12 years coder and I understood very thing eaisly thanks to you

  • @GregoryCarnegie
    @GregoryCarnegie 2 роки тому +3

    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.

  • @googldeed
    @googldeed 2 роки тому

    I can finally get into data simulation now that you made the perfect introduction for me.

  • @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

  • @TAP7a
    @TAP7a 2 роки тому

    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 ;)

  • @si8915
    @si8915 2 роки тому +2

    some day, tim will do "Filosophically Functional Life Forms In Python - Tutorial"

  • @lissankoirala
    @lissankoirala 2 роки тому +6

    45:00 - you made an error here, F = m / a [supposed to be F = m*a]

  • @Stl71
    @Stl71 2 роки тому +1

    No surprise you have so many subscribers. Lots of interesting stuff in that channel, although I am not a python guy.

  • @bvg129
    @bvg129 2 роки тому +5

    You can use strings for common colors in pygame now. Since 2.0

  • @timbeard8457
    @timbeard8457 2 роки тому +3

    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.

  • @leonellg3167
    @leonellg3167 8 місяців тому

    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.

  • @devbites77
    @devbites77 2 роки тому +3

    Great! A fascinating simulation. I would love to see some more physics simulations using forces.

  • @wowgodz-5349
    @wowgodz-5349 2 роки тому +1

    ngl i've been waiting for this

  • @novidtoshow
    @novidtoshow 6 місяців тому +1

    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.

  • @bobmorone461
    @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.

  • @paaritoshjain
    @paaritoshjain 2 роки тому +1

    please do a rocket simulation too!!!

  • @Ansh-Adonis
    @Ansh-Adonis 10 місяців тому

    ill take this a step and a half further, thank you!

  • @tiagosolano9728
    @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.

  • @toul100
    @toul100 2 роки тому

    YOUR OPINION IS VALUED I LOVE THIS

  • @shubhaggarwall
    @shubhaggarwall 2 роки тому

    well the thumbnail helped me revising the force formula thanksss

  • @jacobjohnson7125
    @jacobjohnson7125 3 місяці тому

    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.

  • @absar_ahmad
    @absar_ahmad 2 роки тому +1

    This man have magical powers to know what we are thinking, believe me.

  • @lucidjuice101
    @lucidjuice101 11 місяців тому

    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.

  • @danielkursitis9031
    @danielkursitis9031 2 роки тому +1

    Really enjoy this type of content, keep it up

  • @dimahome544
    @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.

  • @nadeeshani
    @nadeeshani Рік тому

    You are amazing, Tim! Thank you so much for this project and for the way you explained it.

  • @domingezu4687
    @domingezu4687 2 роки тому +1

    Very nice video TIM!

  • @carldavidson-desbiens138
    @carldavidson-desbiens138 2 роки тому

    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.

  • @The007038
    @The007038 2 роки тому +9

    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 :)

    • @ImNotActuallyChristian
      @ImNotActuallyChristian 2 роки тому

      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.

    • @The007038
      @The007038 2 роки тому

      @@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.

    • @The007038
      @The007038 2 роки тому +2

      @@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
      @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.

  • @jdefar3243
    @jdefar3243 2 роки тому +1

    fortunately i knew the math before hand otherwise this would be a lot harder ;D greate video

  • @feelsadgeman
    @feelsadgeman 2 роки тому +1

    I had the same idea, i was going to make this on my final project

  • @Sk8erMorris
    @Sk8erMorris 2 роки тому +1

    ok this is sick, thanks for this one !

  • @AstroBene
    @AstroBene 2 роки тому +1

    *sees the title, screams:* HELL YESS!
    Thanks!

  • @malibaturhan
    @malibaturhan Рік тому

    it was really satisfying even by copying you step by step, thank you

  • @trevorelvis1355
    @trevorelvis1355 2 роки тому

    MY HEART LITERALLY SKIPPED A BEAT WHEN I SAW THIS VIDEO. I WAS SOOOOOOO EXCITED. KEEP 'EM COMING

  • @Andbovi
    @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.

  • @ayushmaanyadav4069
    @ayushmaanyadav4069 2 роки тому +1

    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

  • @LeonardRibeiro25
    @LeonardRibeiro25 Місяць тому

    Appreciate this being available !

  • @natyacodes
    @natyacodes 2 роки тому

    guy teaches almost a million programmers, but doesn't know the difference between star and planet 😂😂
    Nice Video! learned a lot of stuff

    • @playerscience
      @playerscience 2 роки тому

      That's because he is not a nerd LoL.

  • @frankhaug1517
    @frankhaug1517 2 роки тому

    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

  • @lp2045
    @lp2045 2 роки тому

    Now let's see uranus' simulation lol
    Great vid btw

  • @yudianimations
    @yudianimations 2 роки тому

    great tutorial! thanks tim :D
    this also made me understand classes and stuff

  • @LDR_Crafts
    @LDR_Crafts 10 місяців тому

    :. F = mv²/r in circular motion.. So you can actually find the velocity of an object.
    Hence - v = √(rF/m) 😊

  • @hovardlee
    @hovardlee 2 роки тому +1

    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 ?

    • @fjoralbismolli3490
      @fjoralbismolli3490 2 роки тому +1

      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.

    • @Birsic98
      @Birsic98 2 роки тому

      @@fjoralbismolli3490 Smooth

  • @efschannel3043
    @efschannel3043 2 роки тому +1

    Omg I was thinking about this for a long time

  • @muhammadmz8791
    @muhammadmz8791 2 роки тому +1

    thank you tim 🙏

  • @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..

  • @NeonsStyleHD
    @NeonsStyleHD 2 місяці тому

    Excellent video, I learned a lot. Subbed.

  • @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 !

  • @ivolol
    @ivolol 11 місяців тому

    "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

  • @brucea9871
    @brucea9871 11 місяців тому

    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.

  • @sechmascm
    @sechmascm 12 днів тому

    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

  • @gerrymarshall4784
    @gerrymarshall4784 Рік тому

    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.

  • @vfx7t
    @vfx7t 2 роки тому +1

    Good job ! And thanks from Algeria !

  • @趙重茂趙重茂
    @趙重茂趙重茂 2 роки тому +1

    amazing, you're really a genius

  • @ykslooper
    @ykslooper 2 роки тому

    i love you so much tim your videos are amazing. I hope you clsoe time you will 1 millon subs

  • @saranyaghosh2003
    @saranyaghosh2003 2 роки тому

    The title just drew me in!

  • @reubenthomas1033
    @reubenthomas1033 2 роки тому +1

    Awesome! Please do more of these!

  • @joekanaan2548
    @joekanaan2548 2 роки тому

    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.

    • @TanusMorken
      @TanusMorken Рік тому

      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.

  • @manisho7695
    @manisho7695 2 роки тому

    Tim is the best tutor out there for teaching coding

  • @samorwhatever4485
    @samorwhatever4485 11 місяців тому

    You should try commenting as you go to make what youre doing more clear

  • @JamesNewham
    @JamesNewham 2 роки тому +3

    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.

  • @raymondmichael4987
    @raymondmichael4987 2 роки тому +4

    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 🇹🇿

  • @gidartsproduction5439
    @gidartsproduction5439 2 роки тому +1

    Wow, high quality information...

  • @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

  • @professor_ozzy
    @professor_ozzy 2 роки тому

    Ty for the hard work. I learned a lot from this tutorial! :D

  • @J_GB
    @J_GB 2 роки тому

    this was awesome! very cool idea for a simulation

  • @lupamo_Arnold
    @lupamo_Arnold 2 роки тому

    Loved this project. Thanks Tim

  • @MegaMGstudios
    @MegaMGstudios 7 місяців тому

    Really appreciate you turning your facecam off while talking about stuff that's behind your facecam. It's the little things.

  • @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.

  • @mustang5227
    @mustang5227 2 роки тому

    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...

  • @martin-xq7te
    @martin-xq7te 2 роки тому

    Great tutorial Tim. Thankyou

  • @Felix-wo7qz
    @Felix-wo7qz 2 роки тому

    cool tutorial, has been fun to program it!

  • @chrisdanny5180
    @chrisdanny5180 2 роки тому

    This is a brilliant idea

  • @jdefar3243
    @jdefar3243 2 роки тому

    love you'r videos :D they are great I learn so much

  • @tusharpatel2003
    @tusharpatel2003 2 роки тому +1

    It's amazing 😀🤩 bro
    Thank you for this ❤️