- #1
steakbbq
- 1
- 0
Not really homework. But I am programming a game. It is using planetary gravity to make a spaceship go into orbit. I have it so that I find the magnitude of gravity and the direction the planet is in from the ship. I need to make gravity act on the ship in the direction of the planet.
I thin it is something like.
Xpos = cos(angle) + xvelocity;
YPos = sin(angle) + yvelocity;
my head hurts. I can post some of the code to see if you can make sense of it.
//Clalculate Force Of Gravity
forceOfGravity = 1 * ((shipMass * earthMass)/Math.pow(distanceEarth,2));
//Calculate Acceleration
acceleration = forceOfGravity * shipMass;
//Calculate Final Velocity;
fVelocityX = iVelocityX + acceleration * timeStep;
fVelocityY = iVelocityY + acceleration * timeStep;
//Calculate Final Position;
fPositionX = iPositionX + velocity * timeStep;
fPositionY = iPositionY + velocity * timeStep;
//Calculate The X and Y Coordinates Based On Velocity And Angle
//this.x = Math.cos(angleRads);
//this.y = Math.sin(angleRads);
I thin it is something like.
Xpos = cos(angle) + xvelocity;
YPos = sin(angle) + yvelocity;
my head hurts. I can post some of the code to see if you can make sense of it.
//Clalculate Force Of Gravity
forceOfGravity = 1 * ((shipMass * earthMass)/Math.pow(distanceEarth,2));
//Calculate Acceleration
acceleration = forceOfGravity * shipMass;
//Calculate Final Velocity;
fVelocityX = iVelocityX + acceleration * timeStep;
fVelocityY = iVelocityY + acceleration * timeStep;
//Calculate Final Position;
fPositionX = iPositionX + velocity * timeStep;
fPositionY = iPositionY + velocity * timeStep;
//Calculate The X and Y Coordinates Based On Velocity And Angle
//this.x = Math.cos(angleRads);
//this.y = Math.sin(angleRads);