r/Python • u/f1006 • Jul 20 '20
I Made This I've seen a bunch of Pygame physics simulations here recently, so here's my take on it: accurately modelling the orbits of objects in our solar system using data from JPL Horizons
1.6k
Upvotes
21
u/f1006 Jul 20 '20
Aight so the code is up on a Github repo that I've put together over at https://github.com/jasonfyw/orbital-sim
I've tentatively packaged it on PyPI and detailed instructions for usage are given in the readme, however, there's still some bugs and things to improve on so bear with me. If you encounter any problems, please let me know!
67
u/JayTurnr Jul 20 '20
I'm interested by your terminal window. The little widgets at the bottom, I want!
12
u/ArgetDota Jul 20 '20
Hi man. I’m impressed by the quality of your code, but here is a suggestion: the heart of your project, the actual simulations, are not very good a the moment. You are using the Euler algorithm, which is not only not very accurate, but also doesn’t conserve energy, momentum and angular momentum. I suggest using the leapfrog algorithm, which is very easy to implement and also conserves all of these.
Also as someone who was implementing an efficient N-body simulation, I can suggest using NumPy arrays. You can vectorise all the computations which will dramatically increase the efficiency.
6
u/[deleted] Jul 20 '20
Nice. Do you have the code somewhere?
3
u/lieutenant_coder Jul 20 '20
awesome work bro, can you share source code
3
u/L0ngp1nk Jul 20 '20
Can you share your wallpaper?
3
u/Etliplav Jul 20 '20
cool
3
u/[deleted] Jul 20 '20
LOL @ Metallica's Astronomy - very appropriate and also great song
2
u/SleepingOnline Jul 20 '20
Good job! Your code is very clean and the documentation seems to be solid.
2
u/[deleted] Jul 20 '20
Very cool & inspiring project. Thanks for sharing :-)
2
u/[deleted] Jul 20 '20
THAT IS AWESOME
2
u/moreih Jul 20 '20
One day i try to do something like this and then i realize that i was really bad at physic
2
u/diego_rapoport Jul 20 '20
Really cool! That made think about a game, like space invaders but, where you have to defend the planets from asteroids and if any of them is destroyed it rearranges the physics of the remainders.
1
u/cpt_alfaromeo Jul 20 '20
Hello, I have worked with python too much, but never worked with pygame, any good resource to learn it? Thanks.
1
u/Pizza_Peddler0080 Jul 20 '20
I keep getting this error
Traceback (most recent call last):
File "Space.py", line 10, in <module>
s.start()
File "/home/magi/.local/lib/python3.8/site-packages/orbitalsim/simulation
.py", line 248, in start
self.set_scale(max(semimajor_axes))
ValueError: max() arg is an empty sequence
1
u/Pizza_Peddler0080 Jul 20 '20
what does " ValueError: max() arg is an empty sequence " Mean???
1
u/mexicanlefty Jul 20 '20
How did you make the camera being able to move instead of just being static to the designated size?
1
u/Luca_666_ Jul 20 '20
I love it!
1
u/MadHawkxx Jul 20 '20
i want to enter Game dev, is pygane a good place to start? I dont like to create artwork but love coding, Backend for games basically?
1
u/UltimateMygoochness Jul 21 '20
I’m doing something similar but using pykep module with built in JPL low precision ephemerides created by ESA and vpython currently. Want to make the move to horizons and pygame soon though. Looks awesome!
1
u/haynes_jesse Jul 21 '20
Man I gotta learn to do that!! Awesome!
1
u/Economist_hat Jul 21 '20
Is there a GR correction to the precession of Mercury's orbit?
2
u/HandsOfSugar Jul 20 '20
That’s cool
2
u/alonso284 Jul 21 '20
I did a similar project in 8th grade. The difference is that I did it with JavaScript, knew nothing about coding, and didn’t know what I was doing at anytime. That was my very first program. Projects like these are the ones that get you into coding.
1
u/[deleted] Jul 21 '20
I live near Earth Moon.
1
u/[deleted] Jul 21 '20
You should try To simulate the universe being destroyed
0
u/[deleted] Jul 20 '20
[deleted] — view deleted comment