![]() Return Vector.Multiply(-G / position.LengthSquared / position.Length, position) ![]() Where public static Vector GravityAccelerationVector(Vector position) TotalGravity += Sun.Mass * p.Mass * GravityAccelerationVector(p.Position) // Solar acceleration TotalGravity += pN.Mass * p.Mass * GravityAccelerationVector(p.Position - pN.Position) P.Position += Gravity.dT * p.Velocity // Velocity from N - 1/2 The N-body version looks like this: public static void PushPlanets(Planet planets) The Position on iteration N is updated based on the Velocity from iteration N - 1/2, but then the Velocity at iteration N+1/2 is updated based on the Position at iteration N. The trick is that the Position and Velocity aren't at the "same time", which is very common for most integration methods. I'm using, but any custom Vector class will do, as long as it supports basic multiplication and addition. Where "Gravity.dT" is a uniform time step, in an arbitrary measure of time. Velocity += Gravity.dT * GravityAccelerationVector(Position) Here is all you do for a single iteration on a single planet (1-body problem, single planet around stationary sun): public void Push() ![]() The "leap frog" method is very efficient and stable, and works well for any dynamic particle/field system, including plasmas.
0 Comments
Leave a Reply. |