Example #1
0
        private static double[] VectorUnitario(Particula p1, Particula p2)
        {
            double[] aux = new double[p1.posicion.Length];
            double   d   = Interaccion.DistanciaCartesiana(p1, p2);

            for (int i = 0; i < aux.Length; i++)
            {
                aux[i] = (p1.posicion[i] - p2.posicion[i]) / d;
            }
            return(aux);
        }
Example #2
0
        public static double[] Electroestatica(Particula p1, Particula p2)
        {
            double[] f    = new double[p1.aceleracion.Length];
            double   dist = Interaccion.DistanciaCartesiana(p1, p2);

            double[] u = Interaccion.VectorUnitario(p1, p2);
            for (int i = 0; i < f.Length; i++)
            {
                f[i] = (Particula.K * (p1.carga * p2.carga) / (dist * dist)) * u[i];
            }
            return(f);
        }
Example #3
0
        public static double[] Gravitatoria(Particula p1, Particula p2)
        {
            double[] f    = new double[p1.aceleracion.Length];
            double   dist = Interaccion.DistanciaCartesiana(p1, p2);

            double[] u = Interaccion.VectorUnitario(p1, p2);
            for (int i = 0; i < f.Length; i++)
            {
                f[i] = -1 * (Particula.G * (p1.masa * p2.masa) / (dist * dist)) * u[i];
            }
            return(f);
        }
Example #4
0
        public static Particula Interacturar(Particula p1, Particula p2, double[] campo, double delta)
        {
            Particula p = null;

            if (p2 != null && p1.distancia(p2) < 10)
            {
                p  = p1 + p2;
                p1 = null;
                p2 = null;
                Interaccion.Int(ref p, null, campo, delta);
            }
            else
            {
                Interaccion.Int(ref p1, p2, campo, delta);
                if (p2 != null)
                {
                    Interaccion.Int(ref p2, p1, campo, delta);
                }
            }
            return(p);
        }
Example #5
0
 private static void Int(ref Particula p1, Particula p2, double[] campo, double delta)
 {
     double[] g = (p2 != null?Interaccion.Gravitatoria(p1, p2):null);
     double[] e = (p2 != null ? Interaccion.Electroestatica(p1, p2) :null);
     double[] m = Interaccion.Magnetica(p1, campo);
     for (int i = 0; i < p1.aceleracion.Length; i++)
     {
         if (p2 != null)
         {
             p1.aceleracion[i] = (g[i] + e[i] + m[i]) / p1.masa;
         }
         else
         {
             p1.aceleracion[i] = m[i] / p1.masa;
         }
         p1.velocidad[i] = p1.velocidad[i] + p1.aceleracion[i] * delta;
         p1.posicion[i]  = p1.posicion[i] + p1.velocidad[i] * delta;
     }
     g = null;
     e = null;
     m = null;
     GC.Collect();
 }
Example #6
0
        private void InicializaBucle(string RutaPart)
        {
            List <Particula> particulas = new List <Particula>();

            foreach (string f in System.IO.Directory.GetFiles(RutaPart, "*.xml"))
            {
                Particula aux = new Particula(f, new double[] { this.Width / 2, this.Height / 2 }, this._pantalla);
                particulas.Add(aux);
            }
            while (!this._salirBucle)
            {
                this._pantalla.BeginScene();
                this._pantalla.Clear(ClearFlags.Target, Color.Black, 0, 0);
                //hago la interacion entre particulas
                for (int i = 0; i < particulas.Count; i++)
                {
                    for (int j = 0; j < particulas.Count; j++)
                    {
                        if (particulas[i] != null)
                        {
                            if (i != j)
                            {
                                //Particula aux = particulas[i].Interactuar(particulas[j], this._delta);
                                Particula aux = Interaccion.Interacturar(particulas[i], particulas[j], this._campmag, this._delta);
                                if (aux != null)
                                {
                                    particulas[i].Dispose();
                                    particulas[i] = null;
                                    particulas[j].Dispose();
                                    particulas[j] = null;
                                    particulas.Add(aux);
                                }
                            }
                        }
                    }
                }
                GC.Collect();
                for (int i = 0; i < particulas.Count; i++)
                {
                    if (particulas[i] != null)
                    {
                        particulas[i].Dibuja();
                    }
                }
                this._pantalla.EndScene();
                this._pantalla.Present();
                Application.DoEvents();
            }
            for (int i = 0; i < particulas.Count; i++)
            {
                if (particulas[i] != null)
                {
                    particulas[i].Dispose();
                    particulas[i] = null;
                }
            }
            if (this._pantalla != null)
            {
                this._pantalla.Dispose();
                this._pantalla = null;
                GC.Collect();
            }
        }