public static void ApplyForce(this RoundBodyModel body, Time timeInterval = null) { timeInterval = timeInterval ?? DefaultTimeInterval; var f = body.ResultForce.Value; var m = body.Mass.Value; var t = timeInterval.Value; body.Acceleration.Value = f / m; body.Speed.Value += body.Acceleration.Value * t; body.CenterX.Value += body.Speed.Value.X * t + (body.Acceleration.Value.X * t * t) / 2; body.CenterY.Value += body.Speed.Value.Y * t + (body.Acceleration.Value.Y * t * t) / 2; }
public static List<BodiesPair> CalculateForces(this List<BodiesPair> pairs, List<RoundBodyModel> bodies, Time step) { using (PerformanceLogger.Track()) { bodies.ForEach(x => x.ResultForce.Value = new Vector()); ParallelWork.DoWork(pairs, ParallelWork.CalculateGravityForceVectorsWork); bodies.ForEach(x => x.ApplyForce(step)); return pairs; } }
public static void ApplyForce(this BodyWithMass body, Force force, Time time) { var s = body.Speed.Value; var x = body.CenterX.Value; var y = body.CenterY.Value; var m = body.Mass.Value; var t = time.Value; var f = force.Value; body.Acceleration.Value = f / m; body.Speed.Value = s + body.Acceleration.Value * t; body.CenterX.Value = x + body.Speed.Value.X * t + (body.Acceleration.Value.X * t * t) / 2; body.CenterY.Value = y + body.Speed.Value.Y * t + (body.Acceleration.Value.Y * t * t) / 2; }