示例#1
0
        public double Potential(Particle particle)
        {
            var xyDistance = Position - particle.Position;

            // charges with different signs create a negative potential
            return Charge * particle.Charge
                    / Math.Sqrt(xyDistance.LengthSquared + Z * Z);
        }
示例#2
0
        public Vector2D Force(Particle particle)
        {
            var xyDistance = Position - particle.Position;
            if(xyDistance.IsZero) return Vector2D.ZeroVector;

            var xyProjectionCoefficient = xyDistance.Length / Math.Sqrt(xyDistance.LengthSquared + Z * Z);

            // charges with different signs attract each other
            return -Charge * particle.Charge * xyProjectionCoefficient
                    / (xyDistance.LengthSquared + Z * Z)
                    * xyDistance.Unity;
        }
示例#3
0
        public Pendulum(int attractorCount)
        {
            Attractors = new AttractorSet();
            for (int i = 0; i < attractorCount; i++)
            {
                var angle = i * 2 * Math.PI / attractorCount;
                Attractors.Add(new Attractor { Position = new Vector2D(Math.Cos(angle), Math.Sin(angle)) });
            }

            Particle = new Particle { Force = ForceOnParticle };
            Friction = new FluidFriction();
        }
示例#4
0
 public override Vector2D Force(Particle particle)
 {
     return -Coefficient * particle.Velocity.Length * particle.Velocity;
 }
示例#5
0
 public abstract Vector2D Force(Particle particle);
示例#6
0
 private Vector2D ForceOnParticle(Particle particle)
 {
     return Attractors.Force(particle) + Friction.Force(particle);
 }