private void ProcessGobes(MassCenter center) { _globes.ForEach(globe => { globe = _processor.CalculateSpeed(globe, center); globe = _processor.MoveGlobe(globe); }); }
public MassCenter GenerateMassCenter(List <Globe> globes) { var mc = new MassCenter(); mc.Mass = globes.Sum(g => g.Mass); mc.X = globes.Sum(g => g.X * g.Mass) / mc.Mass; mc.Y = globes.Sum(g => g.Y * g.Mass) / mc.Mass; return(mc); }
public Globe CalculateSpeed(Globe globe, MassCenter center) { var distanceSquare = DistanceSquare(center.X, center.Y, globe.X, globe.Y); var vectorSpeed = G * center.Mass / distanceSquare; var distance = Math.Sqrt(distanceSquare); globe.SpeedX += (center.X - globe.X) * vectorSpeed / distance; globe.SpeedY += (center.Y - globe.Y) * vectorSpeed / distance; return(globe); }
private void DrawCenter(MassCenter center) { var vLine = new Line(); vLine.Stroke = Brushes.Black; vLine.X1 = center.X; vLine.X2 = center.X; vLine.Y1 = center.Y - 5; vLine.Y2 = center.Y + 5; vLine.StrokeThickness = 1; canvas.Children.Add(vLine); var hLine = new Line(); hLine.Stroke = Brushes.Black; hLine.X1 = center.X - 5; hLine.X2 = center.X + 5; hLine.Y1 = center.Y; hLine.Y2 = center.Y; hLine.StrokeThickness = 1; canvas.Children.Add(hLine); }
public MassCenter GenerateMassCenter(List <Globe> globes, bool chained) { var mc = new MassCenter(); globes.OrderByDescending(g => g.Mass).ToList().ForEach(globe => { //Первый объект? if (mc.Mass == 0) { mc.X = globe.X; mc.Y = globe.Y; mc.Mass = globe.Mass; } else { mc.X += (globe.X - mc.X) * globe.Mass / (mc.Mass + globe.Mass); mc.Y += (globe.Y - mc.Y) * globe.Mass / (mc.Mass + globe.Mass); mc.Mass += globe.Mass; } }); return(mc); }