- #1

Sword7

- 19

- 2

I am new to this physics forum since I searched for that through Google and found this.

I am figuring out about gravity calculation with 3D coordinations (or vector). I wrote my small program to simulate gravity for flying around the planet Earth. I tried that but a spacecraft quickly went away from Earth instead of orbit. I searched for vector calculation for gravity through the Internet but no luck or not enough information. Does anyone have any complete information about 3D coordination/vector calculation for gravity?

I have two books called "Fundamental of Astrodynamics" and "Orbit Determination for Microcomputers". I still am figuring them out because I am new to vector calculations.

My program for 3D gravity simulation are:

double G = 6.67428e-11;

double M = 5.9742e+24;

double m = 100;

double px, py, pz;

double ax, ay, az;

double Fg, a, r;

px = 7000.0 * 1000;

py = 7000.0 * 1000;

pz = 7000.0 * 1000;

ax = 0.0;

ay = 14.0 * 1000;

az = 0.0;

for(idx = 0; idx < 10000; idx++) {

r = sqrt((px*px) + (py*py) + (pz*pz));

Fg = (G * M * m) / (r * r);

a = Fg / m;

ax += a; ay += a; az += a;

px -= ax; py -= ay; pz -= az;

printf("Spacecraft = %g,%g,%g: Fg = %g N (%g m/s)\n",

px, py, pz, Fg, a);

}

Thanks!

Sword7