- #1
DrCheeto
- 2
- 0
Homework Statement
Hi for fun, and to understand physics better I have scripted a program that replicate gravity exerted from one force (ex the Earth rotating around the sun) and it works well. But now I want to have mutliple bodies that affect gravity and using the same equations it isn't working. To find net gravity I am just finding the force of gravity between say Earth and sun1 and sun2 then adding them up clearly this is wrong because it does not work at all.
Homework Equations
Here is my equations
Code:
'Force
Ftmp = (G * Ball.Mass * Planet.Mass) / (nDist * nDist)
Force.X = Ftmp * (Ball.Pos.X - Planet.Pos.X) / nDist
Force.Y = Ftmp * (Ball.Pos.Y - Planet.Pos.Y) / nDist
'Acceleration
Acceleration.X = Force.X / Ball.Mass
Acceleration.Y = Force.Y / Ball.Mass
'Velocity
Ball.Velocity.X = Ball.Velocity.X + Acceleration.X
Ball.Velocity.Y = Ball.Velocity.Y + Acceleration.Y
'New Position
Ball.Pos.X = Ball.Pos.X - Ball.Velocity.X
Ball.Pos.Y = Ball.Pos.Y - Ball.Velocity.Y
'Return new information
Gravity = Ball
The Attempt at a Solution
My attempt was basically this
Code:
for ncount = 1 to 3
Ftmp = (G * Ball.Mass * Planet(ncount).Mass) / (nDist * nDist)
Force.X = force.x + Ftmp * (Ball.Pos.X - Planet(ncount).Pos.X) / nDist
Force.Y = force.y + Ftmp * (Ball.Pos.Y - Planet(ncount).Pos.Y) / nDist
next