예제 #1
0
        public void Move()
        {
            // Use Current Acceleration to Update Veclocity
            double[] _oldVel = Velocity;
            Velocity = LinearAlgebra.VectorAdd(_oldVel, Acceleration);

            // Use Current Velocity to Update Position
            double[] _oldPos = Position;
            Position = LinearAlgebra.VectorAdd(_oldPos, Velocity);
        }
예제 #2
0
        public static double[] ComputeAcceleration(Body A, Body B)
        {
            // Compute Acceleration of Body A due to Body B
            double G = 6.67e-11;
            double k = G * B.mass;

            double[] _dr = LinearAlgebra.VectorSubtract(A.Position, B.Position);
            double[] _r  = LinearAlgebra.VectorMultiply(
                LinearAlgebra.VectorAbs(_dr), LinearAlgebra.VectorExp(_dr, -3));
            return(LinearAlgebra.VectorScale(_r, k));
        }
예제 #3
0
        private double[] CenterOfMass()
        {
            // Compute [x,y,z] Center of Mass of System
            double _totalMass = TotalMass();

            double[] _centerOfMass = new double[] { 0.0, 0.0, 0.0 };
            for (int i = 0; i < 3; i++)
            {
                // Each of the three components, [x,y,z]
                for (int j = 0; j < bodies.Count; j++)
                {
                    // Go through each body
                    _centerOfMass[i] += bodies[j].mass * bodies[j].Position[i];
                }
            }
            _centerOfMass = LinearAlgebra.VectorScale(_centerOfMass, 1.0 / _totalMass);
            return(_centerOfMass);
        }
예제 #4
0
        private void ComputeAccelerations()
        {
            // Clear all acceleration vectors for step
            for (int i = 0; i < nBodies; i++)
            {
                bodies[i].Acceleration = new double[] { 0.0, 0.0, 0.0, }
            }
            ;

            // Compute Acceleration vectors action on each body
            for (int i = 0; i < nBodies; i++)
            {
                for (int j = 0; j < nBodies; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }                               // Skip if body is the same
                    double[] _oldAcl = bodies[i].Acceleration;
                    double[] _newAcl = Physics.ComputeAcceleration(bodies[i], bodies[j]);
                    bodies[i].Acceleration = LinearAlgebra.VectorAdd(_oldAcl, _newAcl);
                }
            }
        }