public Vector3 GetA(MyPlanet another, float step_time = 1f, float G = 1f) { Vector3 distance = Position - another.GetPosition(); var direction = -Vector3.Normalize(distance); float distanceLength = Vector3.DistanceSquared(Position, another.GetPosition()); Vector3 a; if (distanceLength > Size + another.Size) { a = (G * another.GetMass() * direction) / distanceLength; } else { //这是完全弹性碰撞公式 var m1 = Mass; var m2 = another.Mass; var v1 = Speed; var v2 = another.Speed; var new_v1 = ((m1 - m2) * v1 + 2 * m2 * v2) / ((m1 + m2)); a = (new_v1 - v1) / step_time; } return(a); }
public bool AddPlanet(MyPlanet p) { Vector3 position = p.GetPosition(); if (__NextID > 0) { foreach (MyPlanet old in Environment.Values) { if (Vector3.Equals(old.GetPosition(), position)) { return(false); } } } Environment.Add(__NextID, p); __NextID += 1; return(true); }