Moon motion with Newton laws

Hi,

here is my code which should simulate the moving of moons around a planet.

I am using Newton's law of universal gravitation (http://en.wikipedia.org/wiki/Newton%27s_law_of_universal_gravitation)

public Vector3d calculateAcceleration(){

double r2,r3;

r2 = p.distanceSquared(new Point3d());

r3 = r2 * Math.sqrt(r2);

Vector3d acc =new Vector3d(p);

acc.scale(- parent.mass * Constants.G / r3);

return acc;

}

publicvoid modifyPosition(double intervall){

Vector3d acc = calculateAcceleration();

p.x += v.x * intervall + acc.x * intervall * intervall / 2;

p.y += v.y * intervall + acc.y * intervall * intervall / 2;

p.z += v.z * intervall + acc.z * intervall * intervall / 2;

v.x += acc.x * intervall;

v.y += acc.y * intervall;

v.z += acc.z * intervall;

}

where the parent

is the planet ant this class is the moon. The intervall

is the sample interval.

So essentially I call the modifyPosition and calculate the new position and velocity of the moon based on the mass of the planet (ignoring the moon mass).

The problem is that the path of the moons are not elliptical, but tend to go away from the planet.

Here is some example moons and the deviation after one full rotation (the parameters are: planet - if applicable, mass, velocity, position relative to the ellipse focal point at the closes point):

Orbiter earth =new Orbiter(5.9736e24,new Vector3d(),new Point3d());

Moon moon1 =new Moon(earth, 7.3477e22,new Vector3d(0, 1082, 0),new Point3d(3.63104e8, 0, 0));

: 5715.707726154166 (moon)

Moon moon2 =new Moon(earth, 213800,new Vector3d(0, 3074.66 , 0),new Point3d((42164000), 0, 0));

: 19329.167656623576 (geostationary)

Moon moon3 =new Moon(earth, 213800,new Vector3d(0, 2574.66 , 0),new Point3d((82164000), 0, 0));

: 6930.570266203281 (double geostationary)

Moon moon4 =new Moon(earth, 213800,new Vector3d(0, 3000 , 0),new Point3d((22164000), 0, 0));

: 131903.7051415137 (half geostationary)

distances in m, masses in kg (SI units).

What can be the reason for this?

I can think about the following two:

the double significant digits

the too big sample.

I tend to believe the first as I am using 1 second as the samples.

How can I avoid this kind of deviation?

Thanks for the help

[3329 byte] By [szgya] at [2007-11-26 22:17:45]
# 1
So my second idea was right. If I modified the interval to be 1/100 second then the deviation was also decreased by 1/100th of the values above.However the question remains. How to avoid this (as I don't want to use very short intervals due to performance)?
szgya at 2007-7-10 11:12:05 > top of Java-index,Other Topics,Java Game Development...
# 2

OK, so the solution I found was to use Kepler's laws (http://en.wikipedia.org/wiki/Eccentric_anomaly) for the movement of the moons.

Advantages:

- the moon position can be calculated at exact time positions without interpolation.

- no deviation from the original path is detected - until now :)

Disadvantages:

- the calculations are also not exact

- the process is not working for moons with very distorted paths

- cannot be applied for other objects (on parabolic paths or hyperbolic paths)

szgya at 2007-7-10 11:12:05 > top of Java-index,Other Topics,Java Game Development...
# 3

> What can be the reason for this?

Simplify the problem slightly to circular motion. The speed vector is always tangent to the circle, so if you take a step along it you will find yourself outside the circle. Therefore your integration method (or quadrature rule, since you might want a range of Google keywords) must be able to handle that.

YAT_Archivista at 2007-7-10 11:12:05 > top of Java-index,Other Topics,Java Game Development...
# 4

> > What can be the reason for this?

>

> Simplify the problem slightly to circular motion. The

> speed vector is always tangent to the circle, so if

> you take a step along it you will find yourself

> outside the circle. Therefore your integration method

> (or quadrature rule, since you might want a range of

> Google keywords) must be able to handle that.

OK, I read some related the quadrature rule. It seems complicated (there is some time from my studies in maths).

So I think I will use Kepler's law for celestial objects (orbiting objects), which will be OK for their movement, and for the other objects (on parabolic, hyperbolic paths or ships with concrete destinations, or meteorites which path is chaotic due to gravity) I will use the Newton laws. In this later case the distortion due to the integration errors is not catastrophic as it can be corrected (for ex. by maneuvering the ships to their destination) or can be ignored.

szgya at 2007-7-10 11:12:05 > top of Java-index,Other Topics,Java Game Development...
# 5

Newton's law requires you to (for strict correctness) take ALL sources of gravity into account.

Remember that all bodies exert a gravitational force on all others).

Of course in most conditions you can safely ignore all but a very few of those sources because they are too weak to have an effect at the scale you're investigating (for example, the effect of an Apollo capsule orbiting the moon will have no discernable effect on the orbit of the moon as its mass is too small in relation to all the other sources at work, that same capsule orbiting one of the moons of Mars might very well have an effect because it's mass would no longer be small compared to the mass of that moon(let) itself).

It's been close to 20 years since I made these calculations, so don't expect me to remember the details :)

jwentinga at 2007-7-10 11:12:05 > top of Java-index,Other Topics,Java Game Development...