Exemplo n.º 1
0
        static void Main(string[] args)
        {
#if ANGLE_NORM
            angle a = new angle(Math.PI * 3);
            a += Math.PI * 3;
            a += Math.PI;
            a -= Math.PI * 3;
            a -= Math.PI;
#endif
#if VECTOR_ADD
            vector c = new vector(1, 2);
            vector d = new vector(5, 6);
            c += d;
#endif
#if PHYSICS_TEST
            OrbitalPhysics phys = new OrbitalPhysics(OrbitalPhysics.KMKGS);
            phys.RegisterObject(new GravityObject(new vector(1e40, 0), new vector(0, 2), "Object 1"));
            phys.RegisterObject(new GravityObject(new vector(-1e40, 0), new vector(0, -2), "Object 2"));
            for (int i = 0; i < 100; i++)
            {
                phys.Step(10, i * 1e3);
            }
            vector[] pos = phys.VirtualStep(50, 1000, "Object 1");
#endif
        }
        public void VirtualStep(double dt, double domain, object UID, out List <vector> result, ref bool running, IDebug dbg)          // returns future positions of an object
        {
            running = true;
            foreach (IPhysicsObject a in PhysObjects)
            {
                dbg.Print(a.GetHashCode());
            }
            OrbitalPhysics VirtualCopy = (OrbitalPhysics)this.Clone();

            foreach (IPhysicsObject a in VirtualCopy.PhysObjects)
            {
                dbg.Print(a.GetHashCode());
            }
            List <vector> resultCopy = new List <vector>();

            for (double i = 0; i < domain; i += dt)
            {
                foreach (IPhysicsObject a in VirtualCopy.PhysObjects)
                {
                    foreach (IPhysicsObject b in VirtualCopy.PhysObjects)
                    {
                        if (a != b)
                        {
                            a.Velocity += Gravity(a, b) * dt;
                        }
                    }
                    a.Velocity += a.Acceleration * dt;
                }
                foreach (IPhysicsObject a in VirtualCopy.PhysObjects)
                {
                    a.Position += a.Velocity * dt;
                    if (a.UniqueID.Equals(UID))
                    {
                        resultCopy.Add(a.Position);
                    }
                }
                if (domain - i < dt)
                {
                    dt = (domain - i);
                }
            }
            result  = resultCopy;
            running = false;
        }