r/Python • u/LAMagicx • Oct 10 '19
Just trying to create a orbit system in python and this happened...
449
u/lilgreenwein Oct 10 '19
did you just solve the 3 body problem?
58
u/LAMagicx Oct 10 '19
I highly doubt it. It's more like a simulation of the 3 body problem.
→ More replies (5)152
21
11
u/captain_wiggles_ Oct 10 '19
The 3 body problem has several known solutions for initial start states. The problem is that there's no know way to calculate ALL future states for ALL initial start states. Simulating a particular case is easy enough, but that's not the same as solving the problem.
In the book, they use the human computer thing as a simulation to find what happens next, over the next X years or whatever. Obviously they get it wrong, but that's not the point here. The point is if they had computers then they'd easily be able to calculate future states for their system, since the start state is known. Finally that simulation would grow more and more inaccurate as time progresses, due to the fact that even a 3 body simulation is a prediction (it doesn't take into account other masses, such as asteroids / moons / other planets / etc...), and it's based on a measured start state, and that measurement will have an error.
→ More replies (2)2
Oct 11 '19
this is a similar website. solarsim.net generation algorithms being ran in the background
185
u/the_dancing_squirel Oct 10 '19
You should definitely save this as a full on programm/script
90
u/LAMagicx Oct 10 '19
Oh yeah! I've just made a new file and copied it over. Now just messing with more variables.
73
u/the_dancing_squirel Oct 10 '19
Do you mind sharing it? Like on GitHub or somewhere else? Just out if curiosity
20
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
17
6
→ More replies (3)1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
8
u/Who_The_Fook Oct 10 '19 edited Oct 11 '19
Bruh please share the code, I'd love to see how this works. Even if it's for something close to but not the same as this. I'm out here still learning Java rn but this shit is so cool looking.
→ More replies (1)2
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)9
u/YellowOnion Oct 11 '19
made a new file and copied it over.
Learn git, it's a lot easier to track your changes, plus you can revert if you decide later you changes were a mistake.
→ More replies (1)1
u/sebaseek Oct 11 '19
Share it on github! I will fork it
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
46
Oct 10 '19
You've created life, my friend
27
u/LAMagicx Oct 10 '19
Funnily enough I'm studying emergence for a school project. And this is just the start
21
6
4
u/BlitzFuer Oct 11 '19
Futuristic beings materialize in your office “TimeLord you must come with us, we will explain everything, but your life, and our existence is in danger.”
→ More replies (1)
37
u/psharpep Oct 10 '19 edited Oct 10 '19
Cool work!
A word of advice: assuming you're modeling gravity with a 1/r2 kernel function, it looks like you've got a lot of error due to your time integration scheme here! (The most immediately apparent indication: the orbital decay shows that the total energy of your system is changing with respect to time, when it should be fixed.)
What integration scheme did you implement here? Maybe you could try a higher-order method like RK4?
An alternative would be to use kinetic energy, location (potential energy), and direction of motion as your state variables, or to do a total-energy compensation step at each timestep!
15
u/LAMagicx Oct 10 '19
Thanks! The kinetic and potential energy sounds great I will try to implement that for the actual system. This is more of a sandbox type simulation because I'm changing the force of gravity to become more and more powerful, hence why the orbital decay. In this I'm not trying to model an orbit however the base of it is an orbital model.
btw I have no idea if its a kernal function or what a integration scheme is and the RK4 method is beyond me (for now).
7
u/namesnonames Oct 10 '19
I'd have to guess you are doing Euler integration then. Could you share the source?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)→ More replies (1)5
u/masasin Expert. 3.9. Robotics. Oct 10 '19
You're probably using Euler. Try leapfrogging? And RK4 has complicated symbols, but it's easy when you translate it to code. (See if you can find a code example.)
5
u/billsil Oct 11 '19
RK4 is notoriously inaccurate for orbits. A single orbital period can have large truncation error, let alone 10000. It’s better than Euler though. It’s not energy preserving though and there are methods that are similar to RK4 in complexity that are.
→ More replies (4)7
u/AnomalousLurker Oct 10 '19
Would a symplectic integration scheme not work better here?
3
u/psharpep Oct 11 '19
Yes, it would - that'd be better than either Euler or RK4 for this kind of problem since it's inherently conservative!
You'd have to reformulate the physics of the problem with some sort of conservation law (i.e. move towards Hamiltonian mechanics), which is kind of what I was trying to hint at with my last idea there.
→ More replies (1)3
Oct 11 '19
you need a symplectic integration scheme for this to work. energy is not properly conserved in RK4. the easiest one is probably velocity verlet which is second order but symplectic.
→ More replies (1)2
u/novel_eye Oct 10 '19
Mind sharing some links? I’m doing an orbit simulation for the solar system and I’ve been using Verlet integration but would like to do some more classical mechanics based integration. Having trouble finding a link with enough rigor for good implementation without bogging me down with physics I’m unfamiliar with.
11
u/squidly-diddly97 Oct 10 '19
sauce ?
[source code(if you don't mind, please) ?]
EDIT: politeness
1
u/LAMagicx Oct 11 '19
Of course my dear kind polite friend, you can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)
19
u/nandrajrathod Oct 10 '19
It's Awesome. Can you please pass the code?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)
6
u/Pissed_Off_Penguin Oct 10 '19
Noob here! Is pygame a good way to plot data quickly? I'm working on a Lidar thing and I would like to find a way to plot the scans a little faster than matplotlib scatter.
3
u/LAMagicx Oct 10 '19
I was going to suggest matplotlib but seeing as you've already done that then pygame is the next step. Just have to add a bit more code to make it possible.
3
Oct 10 '19
Dude, that is awesome! Like everyone else is saying: would you mind sharing the sourcecode?
8
u/LAMagicx Oct 10 '19
Yeah I know but if I do that I'm going to spruce it up and make sure it's understandable.
3
Oct 10 '19
Totally ok with me!
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
113
38
u/plontx Oct 10 '19
Did you stop recording bc it stabilizes at that point? I feel like it ended too soon, I'd love to watch this for hours!
26
u/djm2491 Oct 10 '19
Dude send this to one of the famous DJs and have them throw it on screen at a rave. People would lose their minds
19
u/reinaldo866 Oct 10 '19
"Finally, I've mastered mathemathics and applied programming science, I've built the best galaxy simulation piece of software ever created, I'll give it to this DJ to play it on a Dubstep concert"
5
→ More replies (1)2
15
Oct 10 '19
I love how your rosette explodes into the Eye of Sauron after it destabilizes. You've doomed us all.
8
2
u/frany_RL Oct 10 '19
Hey!! Thats really nice, can you pass the code?
2
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/LAMagicx Oct 10 '19
I understand that many of you are asking for the source code which I plan to release to github however it would be my first public code post and I'm wondering if you have any tips for the commenting or 'tidying' up that I should do? (or do I just post it as it is and see what happens?) Could really use some guidelines for this sort of thing.
3
u/mriswithe Oct 10 '19
Honestly for this just putting it in a git repo with whatever you have is fine. We aren't after a perfectly documented production dependency. If you want to improve it from there you can make commits along the way and can always fall back to what you had
3
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/chinpokomon Oct 12 '19
Any tips for running it?
The source has Unicode, which Python 2 didn't like. I tried Python 3, but PyGame didn't like that. So I went back to Python 2 and renamed the Unicode symbols. Then it failed because it looks like it uses some other Python 3 version of PyGame.
Might as well just ask at this point.
1
u/LAMagicx Oct 12 '19
I running python 3.6 with pygame so can't tell you what you're doing wrong really.
→ More replies (1)
1
u/LAMagicx Oct 11 '19
Originally just a simple orbital system but here gravity becomes more powerful hence the decay.
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
4
1
u/GlazCoin Oct 10 '19
Nice Could you share the code and how you made it, please.
2
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
Oct 10 '19
Can I get the source code?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)
1
u/Vegerot Oct 10 '19
Wanna post the source code?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/ishman123 Oct 10 '19
are you able to share code?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/meshikhah Oct 10 '19
source code pls
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/kielerrr Oct 10 '19
Can you link the code? Would love to try running it!
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/Acid_Monster Oct 10 '19
Can you share the code for this?
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/vEnoM_420 Oct 10 '19
I'm new to python. Can you tell me what did you to produce this pattern? Not asking for the code but how did you manage to get those different colors? Just curious.
2
u/LAMagicx Oct 10 '19
the funny thing is, on my computer screen there is only 3 colours, red, green and blue. In the video it seems like they blend together to form a multicoloured pattern.
1
u/jamee42 Oct 10 '19
Would love to see the longer version.. assume it just goes on and on and .....
1
1
u/martinLBarranco Oct 10 '19
Can you let us please see the code, that's quite beautiful and I'd like to see what I can do to expand and improve this.
2
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
1
u/Gingevere Oct 10 '19
Why do the orbits decay? Are you simulating tidal friction?
1
u/LAMagicx Oct 11 '19
They are now decaying its just that gravity is becoming stronger and stronger so thier orbits are being pulled closer together
1
u/0xD3adB33f_ Oct 10 '19
Whoa that's super awesome! What libraries are working with on this project? I'm assuming perhaps matplotlib at the very least?
1
1
u/TIBTHINK Oct 11 '19
Code?
It looks really cool
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/bastawhiz Oct 11 '19
Are the sudden changes in velocities/directions of the particles due to the algorithm or does it happen because of the way floating point numbers work?
1
u/LAMagicx Oct 11 '19
More of how the algorithm works. Gravity becomes more and more powerful and when the particles touch they then explode outward.
1
Oct 11 '19
Code pls which made this
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
Oct 11 '19
Amazing... How did begin to code this, could be a great learning opportunity for others if your willing to share.. My self I'm super interested.
2
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
→ More replies (1)1
1
Oct 11 '19
What did you use? Is it possible to simulate a solar system somehow?
1
u/LAMagicx Oct 11 '19
That was my initial intention but this turned out to be much better
→ More replies (2)
1
1
u/magespawn Oct 11 '19
Share the code, if you please.
2
1
u/LAMagicx Oct 11 '19
You can now find the source code at https://github.com/LAMagicx/OrbitalArt , I would love to see what you can come up with.
1
u/hello-i-am-turtle Oct 16 '19
Beginner here would this be a good project to test how much you know?
2
u/LAMagicx Oct 16 '19
Yeah of course, a simple orbital system is a great challenge. For testing how much you know it is also pretty good because there are many different levels of "difficulty" you can have a single body with one or more satellites orbiting it and then add the attractions between the satellites and so on.. Any challenging project is good for a beginner.
→ More replies (1)1
3
3
3
3
u/14446368 Oct 10 '19
No idea why, but this reminded me of the whirring machinery of Atlantis, and the Nur-ab-Sal pendant/god from Indiana Jones and the Fate of Atlantis.
1
1
4
2
2
2
2
2
2
2
2
2
2
u/Guinness Oct 10 '19
The center is a black hole where you divided by zero.
This has summoned the great byte monster.
The great byte monster will eat all data in the universe.
Good job.
2
2
2
2
2
2
2
2
u/Keanar Oct 11 '19
Scott Derrickson called, he wants to buy your code for the portal of the next Doctor Strange
2
2
u/CapitanNexus Oct 22 '19
I dont know where you from or how they grade in america if u are from america but in uk you would get A** even tho there is no ** in grades
3
u/Im_oRAnGE Oct 10 '19
Please don't use v.redd.it. I can't watch this in anything other than 144p, even if I change the setting to 1080p it doesn't load in higher quality. And it still takes ages to load even in low quality.
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
u/octavio2895 Oct 10 '19
The chaotic ending is probably due to a relatively large time-step when the bodies are moving fast. There are methods to implement variable size time-steps but I know nothing about those. Maybe you should time-step proportional to the speed of the bodies?
1
1
1
1
1
1
1
1
711
u/Grow-away123 Oct 10 '19
When my code messes up I get error messages meanwhile you’re over here making art