public static void Step() { var quadtree = Quadtree.Build(Particles, Min, Max); Parallel.ForEach(Particles, particle => { var a = Particles.ToList(); a.Remove(particle); particle.Velocity += AddThem(a.Select(x => quadtree.GetForce(particle, x) / particle.Mass).ToList()); particle.Position += particle.Velocity; }); }
public static Quadtree Build(List <Particle> particles, Vector2 min, Vector2 max) { if (particles.Count == 0) { return(new Quadtree(min, max)); } Quadtree quadtree = new Quadtree(particles[0], min, max); for (int i = 1; i < particles.Count; i++) { quadtree.Insert(particles[i]); } quadtree.Compute(); return(quadtree); }