Exemplo n.º 1
0
        public void solveProblem1()
        {
            Io       = new Moon("Io", Input[0]);
            Europa   = new Moon("Europa", Input[1]);
            Ganymede = new Moon("Ganymede", Input[2]);
            Callisto = new Moon("Callisto", Input[3]);
            Moons    = new Moon[Input.Length];
            Moons[0] = Io;
            Moons[1] = Europa;
            Moons[2] = Ganymede;
            Moons[3] = Callisto;

            const int numberOfTimeSteps = 1000;

            for (int i = 1; i <= numberOfTimeSteps; i++)
            {
                doTimeStep();

                /*
                 * Console.WriteLine("");
                 * Console.WriteLine("Step " + i);
                 * Console.Write("Pos " + Moons[0].Pos);
                 * Console.Write("Vel " + Moons[0].Velocity);
                 */
            }

            /*
             * Console.WriteLine(Moons[0].PotentialEnergy);
             * Console.WriteLine(Moons[0].KineticEnergy);
             * Console.WriteLine(Moons[0].Energy);
             */
            Console.WriteLine("End result= " + calculateTotalEnergy());
        }
Exemplo n.º 2
0
        public void applyGravity(Moon otherMoon)
        {
            double velX = Velocity.X;
            double velY = Velocity.Y;
            double velZ = Velocity.Z;

            double otherVelX = otherMoon.Velocity.X;
            double otherVelY = otherMoon.Velocity.Y;
            double otherVelZ = otherMoon.Velocity.Z;

            if (Pos.X > otherMoon.Pos.X)
            {
                velX      -= 1;
                otherVelX += 1;
            }
            else if (Pos.X < otherMoon.Pos.X)
            {
                velX      += 1;
                otherVelX -= 1;
            }

            if (Pos.Y > otherMoon.Pos.Y)
            {
                velY      -= 1;
                otherVelY += 1;
            }
            else if (Pos.Y < otherMoon.Pos.Y)
            {
                velY      += 1;
                otherVelY -= 1;
            }

            if (Pos.Z > otherMoon.Pos.Z)
            {
                velZ      -= 1;
                otherVelZ += 1;
            }
            else if (Pos.Z < otherMoon.Pos.Z)
            {
                velZ      += 1;
                otherVelZ -= 1;
            }

            Velocity           = new Vector3D(velX, velY, velZ);
            otherMoon.Velocity = new Vector3D(otherVelX, otherVelY, otherVelZ);
        }