Hi, sorry for posting another thread. I want this one to be more specific. Also, it's on a different question than my last thread.

I'm making a physics engine for class. The GUI was provided by my professor.

I'm trying to implement gravity.

I'm doing:
Code:
				case ASTEROID_ID: //m1 = SPACESHIP_MASS, m2 = ASTEROID_MASS
					forceX[i] += GRAV_CONST * ( (SPACESHIP_MASS * ASTEROID_MASS) / ( sqrt( (x[i]-x[u])*(x[i]-x[u]) + (y[i]-y[u])*(y[i]-y[u]) ) ) ) * cos( atan( (y[u]-y[i]) / (x[u]-x[i]) ) );
					forceY[i] += GRAV_CONST * ( (SPACESHIP_MASS * ASTEROID_MASS) / ( sqrt( (x[i]-x[u])*(x[i]-x[u]) + (y[i]-y[u])*(y[i]-y[u]) ) ) ) * sin( atan( (y[u]-y[i]) / (x[u]-x[i]) ) );
					break;
Force of Gravity = 1/8300((m1*m2)/r^2)
1/8300 is an approximation of the gravitational constant

Then, I have to split that force into a force of X and a force of Y (which I later compute into a velocity of x and a velocity of y)

r is the distance between the two masses (sqrt( (x[i]-x[u])*(x[i]-x[u]) + (y[i]-y[u])*(y[i]-y[u]) )

I have to find the angle for dividing the force into forceX and forceY
So: angle = atan( (y[u]-y[i]) / (x[u]-x[i]) )

Then I have to find forceX:
cos(angle) * gravityForce = forceX

ForceY:
sin(angle) * gravityForce = forceY


The problem is that none of this works.
When I load up the program with this implemented, all objects are stuck on one point (0,0 I believe.. Which is the starting point of the spaceship)

I must be doing this completely wrong, and it's way over my head so I'm not surprised really.

Does anyone know what I might be able to try?