Ejemplo n.º 1
0
        public static Vector3[] GetAs(MyPlanet p1, MyPlanet p2, float step_time, float G = 1f)
        {
            Vector3 a1 = p1.GetA(p2, step_time, G);
            Vector3 a2 = p2.GetA(p1, step_time, G);

            Vector3[] all = new Vector3[2] {
                a1, a2
            };
            return(all);
        }
Ejemplo n.º 2
0
        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);
        }