public void GetNext(Vector2 F, double time, planet b) { velocity.X += F.X * time / mass; velocity.Y += F.Y * time / mass; location.X += velocity.X * time; location.Y += velocity.Y * time; }
public Form1() { i = 0; time_tick = 1; this.Text = "弹球模拟"; this.Size = new System.Drawing.Size(800, 600); graphics = this.CreateGraphics(); timer1 = new Timer(); timer1.Interval = time_tick; timer1.Tick += new EventHandler(TimePass); timer1.Start(); a = new planet(new Point(200, 300), new Vector2(-30, 100)); a.Texture = new SolidBrush(Pens.Blue.Color); b = new planet(new Point(500, 300), new Vector2(30, -50)); b.Texture = new SolidBrush(Pens.Black.Color); b.mass = 10; l1 = new Label(); l1.AutoSize = true; this.Controls.Add(l1); l2 = new Label(); l2.AutoSize = true; this.Controls.Add(l2); time = new Label(); time.Location = new Point(0, 0); time.AutoSize = true; this.Controls.Add(time); }
public Vector2 GetF(planet b) { Vector2 S = new Vector2(b.location.X - this.location.X, b.location.Y - this.location.Y); double distance = Math.Sqrt(S.X * S.X + S.Y * S.Y); Vector2 F = new Vector2(0, 0); int G = 300 * 300 * 100; F.X = G * this.mass * b.mass / (Math.Pow(distance, 3)) * S.X; F.Y = G * this.mass * b.mass / (Math.Pow(distance, 3)) * S.Y; return(F); }