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

