Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relative gravity

I've started using jMonkey engine recently, which is very nice. But I got stuck trying to implement relative gravity.

I want to make planets orbiting around each other (not necessarily in perfectly circular orbit, depends on velocity). So every object should affect other objects.

What I have right now:

turning off global gravity

bulletAppState.getPhysicsSpace().setGravity(Vector3f.ZERO);

initializing spheres and adding to physics space

Sphere sphere = new Sphere(50, 50, 5);
Geometry sun = new Geometry("Sun", sphere);

sun.setMaterial(stone_mat);
rootNode.attachChild(sun);
sun.setLocalTranslation(0, 0, 0);

sunPhysics = new RigidBodyControl((float) (50*Math.pow(10, 5)));
sun.addControl(sunPhysics);
bulletAppState.getPhysicsSpace().add(sunPhysics);

Geometry mercury = new Geometry("Mercury", sphere);

mercury.setMaterial(stone_mat);
rootNode.attachChild(mercury);
mercury.setLocalTranslation(15f, 0, 0);

mercuryPhysics = new RigidBodyControl((float) (5));
mercury.addControl(mercuryPhysics);
bulletAppState.getPhysicsSpace().add(mercuryPhysics);

I noticed that there is method setGravity in RigidBodyControl class, but it just sets the direction. So object goes that way until it disappears.

I am really looking forward for answers.

like image 948
Česlovas Lopan Avatar asked Sep 11 '12 13:09

Česlovas Lopan


People also ask

Is specific gravity and relative gravity same?

Density is the specific property of matter and it uses the ratio of mass to the volume of matter. On the other hand, specific gravity or relative density is the measurement of density with respect to a density of pure water.

What is the relative gravity of water?

Because water at 4 degrees Celsius is the standard scientists use to determine specific gravity, it follows that its specific gravity is 1.

What is the difference between relative density and specific gravity?

Density is the property of matter represented by a ratio of mass to a unit volume of matter. Specific gravity which is also called relative density is a measure of density with respect to the density of pure water. There are many properties of water, such as conductivity of water and many more.


1 Answers

The law of gravitation says F = G (m1 * m2) / r^2 where m1 and m2 are the masses of the two bodies, and r is the distance. G is the gravitational constant.

Newton's second law says F = m * a, so if we put them together, the body with mass m1 would experience an acceleration of a = G * m2 / r^2 from gravitational pull from the body with mass m2.

Now, what you would have to do is: In each step of the simulation, for each body, sum up the as for each other body and apply that acceleration to the body's velocity.

a(body1) = G * sum[ mass(body2) / dist(body1, body2)^2 , for each body2 ]
like image 167
tobias_k Avatar answered Sep 30 '22 13:09

tobias_k