Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  any experience with gravity simulations?  (Read 5391 times)
0 Members and 1 Guest are viewing this topic.
Offline Rakiayn

Senior Newbie





« Posted 2013-11-09 16:35:52 »

So I have a gravity simulation in which multiple objects are created and are attracted to eachothers by the laws of gravity.
now I am having problems to create stable systems with more then 2 objects.
the goal of my program is to create a stable solar system with multiple planets and moons.

for test purposes I create 1 star, and one planet with a moon.
with some code I let them orbit eachother as they should.
now it looks good in the beginning. the planet orbits the star and the moon orbits the planet
but the problem is that the star has a gravitational pull on the moon. that causes the moon to be pulled out of its circulair orbit. the moon eventually crashes on the planet.

so my question is. is there anyone here who has experience with creating stable systems in a gravity simulations? do you have any tips for me? or is not really possible to make (which I suspect now)
Offline saucymeatman
« Reply #1 - Posted 2013-11-09 17:21:29 »

Ive spent most of the last couple weeks working on physics for my game engine.
I do think its possible, but I dont think it would be easy. I find that the best way to start is with momentum.
I established a momentum controller in my physics object like so(psuedocode, obviously) :

[assume airResistance = .97 and xMomentum = 10]
[this runs ever 5 miliseconds]
[handle xMomentum and yMomentum seperatly]
1  
2  
3  
4  
5  
6  
addYMomentum(-gravity);
if (yMomentum != 0)
  move(this, yMomentum);
  yMomentum *= airResistance;
  if (yMomentum [is close to] 0)
    yMomentum = 0;


from there, maybe you could modify my momentum strategy to work with a center of gravity, and apply momentum respectively.
I you want to use any of my code, feel free. You dont have to give me credit.
https://github.com/Saucymeatman/EntropyGameEngine

I know this dosent solve you problom, but I hope that this helps at least.
Offline pploco1996

Junior Member


Medals: 2
Exp: 1 year



« Reply #2 - Posted 2013-11-09 18:52:50 »

Well you can always use box2d for that, but it's understandable if you want to create your own physics engine for learning purposes.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Rakiayn

Senior Newbie





« Reply #3 - Posted 2013-11-09 19:01:49 »

I already wrote the physics for it and it is working fine.
the problem is I am looking for the starting velocity of the moon,star and planet so that a stable system emerges.
a system with 2 objects is no problem. even a system with 1 large object and 2 equally massed smaller objects orbitting eachother works fine.
that is because the 2 smaller objects have a center of gravity so it is in equilibrium with the 3rd larger object.
but when the mass of these 2 objects are not equal (like earth and moon) the system becomes unstable rather quickly.
Offline davedes
« Reply #4 - Posted 2013-11-09 19:32:32 »

Perfectly stable physics is kind of difficult.

Have you considered "faking" the orbit with something like verlet constraints? I guess it depends on the level of realism you're trying to achieve.

Offline Rakiayn

Senior Newbie





« Reply #5 - Posted 2013-11-09 20:00:56 »

It doesnt have to be a perfectly stable system.
I just want it to be semi stable so that body's do not collide or get swung out of the system before a descent amount of simulation time has gone by.
faking is probally the solution I have to go for.

Offline Danny02
« Reply #6 - Posted 2013-11-09 20:06:24 »

No it is not possible to have a stable calculation. You might get some very good one, but why bother?

You could just calculate all the ellipses for the planets and be done with it. No real simulation just a pre-calculated solar system.

here a cool blog post describing different gravity integration methods
Offline quew8

JGO Coder


Medals: 29



« Reply #7 - Posted 2013-11-09 20:42:06 »

No it is not possible to have a stable calculation. You might get some very good one, but why bother?

Perfect is never attainable. Very good is all we can ever get. I think the reason one should bother is to produce a dynamic simulation capable of working under all kinds of situations. For example, maybe one day you get the urge to collide a couple of solar systems together - in that situation I don't think that simple orbital equations are going to cut it.

As for starting off with a velocities, masses and radii to create stable orbits, I'm sure you can create a few equations, make up some masses and radii and then brute force the solution for a set of velocities. You don't need to rely on all these computationally simpler methods so you can do the integration properly.
Offline Danny02
« Reply #8 - Posted 2013-11-09 21:29:29 »

yeah right, I would like to see how you crash two solar systems together ...
Offline lcass
« Reply #9 - Posted 2013-11-09 21:34:33 »

yeah right, I would like to see how you crash two solar systems together ...
Challenge accepted lol!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kramin42
« Reply #10 - Posted 2013-11-10 07:08:53 »

Depending on the masses and distances some systems could be inherently unstable too (no matter how you set the velocities). e.g. most orbits around the Moon are unstable. Try setting all the masses/distances/velocities etc. in proportion to the Sun/Earth/Moon system and see if it is stable in your simulation.

"All science is either physics or stamp collecting." - Ernest Rutherford.
CodeGolf4k
M4nkala
Offline Roquen
« Reply #11 - Posted 2013-11-10 12:04:32 »

Orbits = Kepler
Offline Rakiayn

Senior Newbie





« Reply #12 - Posted 2013-11-10 13:43:23 »

yeah right, I would like to see how you crash two solar systems together ...
Challenge accepted lol!

I would like to see that too Smiley

Depending on the masses and distances some systems could be inherently unstable too (no matter how you set the velocities). e.g. most orbits around the Moon are unstable. Try setting all the masses/distances/velocities etc. in proportion to the Sun/Earth/Moon system and see if it is stable in your simulation.

good idea, I will try it. but I suspect it will still be unstable, although it might be stable for a longer time because the suns influence is much weaker. I suspect that in the case of the earth and moon other factor play a role that stabilizes the orbit. like the tides or something. google doesnt give me an answer to this question.




Offline Danny02
« Reply #13 - Posted 2013-11-10 13:56:49 »

My point was that you wouldn't simulate such thing with some floating rigid spheres. When two orbital bodies collide they don't just bounce off each other, they get deformed and ripped apart, something which you would handle as some special case if at all.

So as I said just calculate the orbits and let the planets position be calculated by their functions. And as roquen said use this => en.wikipedia.org/wiki/Kepler_orbit
Offline Rakiayn

Senior Newbie





« Reply #14 - Posted 2013-11-10 18:31:40 »

thank you all for your input.
I will either use kepler, or use newton as I currently do. but then I will have to accept more simple systems without moons.

Offline Roquen
« Reply #15 - Posted 2013-11-10 20:20:06 »

Earth's moon can be modeled by Kepler's.  The two bodies are the active and dominate bodies.
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #16 - Posted 2013-11-12 09:27:37 »

So not to negate what was already said. But even with super accurate integrators, or even perfect math, under the laws of gravity 3 body systems are not stable. There are like 3 exact configurations of 3 body's that are stable as far as mathematics are concerned but perturb them in any way.... 

Its called the 3 body problem. http://en.wikipedia.org/wiki/Three-body_problem

However in reality there is typically only one important body and the rest can be ignored. For example when considering the earths orbit around the sun, we can even ignore the earths mass and we have approximately a 1 body system with an infinitely light mass orbiting it. When considering earth, moon and sun we can consider earth moon as a system, then the earth/moon center of mass orbits the sun. If we want to add Jupiter to the mix, we ignore the effects of earth on Jupiter  etc.

However full simulations are also possible, BUT you do it different from just brute force accuracy. You need the integration method to be reversible to conserve important properties of the system (mostly momentum). So a 2nd order leapfrog is typically way better than a 4th order RK method. 

But do you need this accuracy for a game? Using parametric orbits probably works better anyway.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline Rakiayn

Senior Newbie





« Reply #17 - Posted 2013-11-15 04:37:41 »

very interresting.
can you explain more about that last part?. I dont understand it.
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #18 - Posted 2013-11-15 14:32:24 »

I assume you talking to me and you are asking about the simulation stuff. Basically you can do a PhD thesis on this stuff. Its that hard to get accurate and right.

But a simple integrator, just use a 2nd order leap frog. If you don't know what that is. Stick with parametric representations.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline jmguillemette
« Reply #19 - Posted 2013-11-15 16:07:23 »

is the purpose of your game to model a solar system.. or to give the user the impression the solar system has gravity....

If its the first.. then your in for some challenges (hard ones) but it is do able.

if the later, then dont base the orbits of your planets on real physics .. fake it.
Instead have the planets rotate each other in a fixed way.. and use collision boxes to determine when gravity will affect other objects in the game. In this way the hard
part of establishing stable orbits is gone.. but the illusion of physics is maintained.

j.

-=Like a post.. give the author a medal!=-
Offline trollwarrior1
« Reply #20 - Posted 2013-11-15 17:45:00 »

If the moon crashes into the planet, because it is attracted by the sun, you should move the planet + moon away from the sun. Or make the moon smaller. Or make the planet bigger.
Offline Roquen
« Reply #21 - Posted 2013-11-15 18:08:05 »

I repeat: Kepler's.  Don't waste your time making simple problems hard.
Offline delt0r

JGO Knight


Medals: 26
Exp: 18 years


Computers can do that?


« Reply #22 - Posted 2013-11-15 18:44:08 »

To back up Roquen's point. NASA and co use these simple parametric orbits for everything from space probes to knowing where to point that dish to get signals of a satellite. That is you know they are ellipsis and how fast it goes at different parts of the ellipses. Of course i think that is too much. Just stick to circles. If its good enough for multi million dollar space missions surely its enough for a game.

In Eve planets don't even move.

I have no special talents. I am only passionately curious.--Albert Einstein
Offline jmguillemette
« Reply #23 - Posted 2013-11-15 19:34:52 »

interesting point about eve...

didnt know that .. barely ever played the game.. but its a gorgeous looking one.


-=Like a post.. give the author a medal!=-
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Riven (9 views)
2014-07-29 12:53:52

Dwinin (7 views)
2014-07-29 10:59:34

E.R. Fleming (23 views)
2014-07-29 03:07:13

E.R. Fleming (9 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (51 views)
2014-07-17 23:47:54
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!