コード例 #1
0
        /// <summary>
        /// Creates a fresh new list of particles with random positions and mass.
        /// </summary>
        /// <param name="NumParticles">The number of particles to create</param>
        /// <param name="GridSize">The "radius" of the grid</param>
        /// <param name="StartingVelocity">The starting velocity of particles</param>
        public static List<Particle> DEBUG_InitializeParticles(int NumParticles, double GridSize, double StartingVelocity, int Dimensions)
        {
            //Create a new list of particles
            List<Particle> NewList = new List<Particle>(NumParticles);

            //Create a new property type called "Mass" that will be inherited by all of our particles
            PropertyType Mass = new PropertyType("Mass", 0, double.PositiveInfinity, false, false);

            //Create charge
            PropertyType Charge = new PropertyType("Charge", double.NegativeInfinity, double.PositiveInfinity, false, false);

            //For each requested number of particles:
            for (int i = 0; i < NumParticles; i++)
            {
                //Create a new 3D particle
                Particle NewParticle = new Particle(Dimensions);

                //Randomize a 3D starting position within the given grid size
                NewParticle.Position = SimMath.RandomEuclideanPosition(Dimensions, GridSize);

                //Randomize the velocity if given
                NewParticle.Velocity = SimMath.RandomDirection(3);
                NewParticle.Velocity.Magnitude *= StartingVelocity;

                //Set the size for the particles
                NewParticle.Radius = 1;

                //Give each particle a random mass and charge
                ParticleProperty NewParticleMass = new ParticleProperty(Mass);
                ParticleProperty NewParticleCharge = new ParticleProperty(Charge);
                NewParticleMass.Value = SimMath.GenerateRandomDouble(1, 10000);
                int Choice = SimMath.GenerateRandomInteger(1, 3);
                if (SimMath.GenerateRandomBool())
                {
                    NewParticleCharge.Value = PhysicsConstants.ElementaryCharge * 1E12;
                }
                else
                {
                    NewParticleCharge.Value = -PhysicsConstants.ElementaryCharge * 1E12;
                }
                NewParticle.Properties.Add(NewParticleMass);
                NewParticle.Properties.Add(NewParticleCharge);

                //Add a copy of this particle to the list of particles
                NewList.Add(NewParticle);
            }
            return NewList;
        }
コード例 #2
0
 /// <summary>
 /// Creates a new particle property of a particular type and value
 /// </summary>
 /// <param name="PType">The particle property type (such as "mass" or "charge")</param>
 /// <param name="Value">The value associated with the new property</param>
 public ParticleProperty(PropertyType PType, dynamic Value)
 {
     this.Type = PType;
     this.Value = Value;
 }
コード例 #3
0
 /// <summary>
 /// Adds a property of a particular type and value to this particle
 /// </summary>
 /// <param name="PType">The type of property to add (such as "mass" or "charge"</param>
 /// <param name="Value">The value of the new property</param>
 public void AddProperty(PropertyType PType, dynamic Value)
 {
     if (PType == null) return;
     this.Properties.Add(new ParticleProperty(PType, Value));
 }
コード例 #4
0
 /// <summary>
 /// Creates a new particle property of a particular type.
 /// </summary>
 /// <param name="PType">The particle property type (such as "mass" or "charge")</param>
 public ParticleProperty(PropertyType PType)
 {
     this.Type = PType;
 }