Пример #1
0
    public _Point ForceOn(Particle particle, Particle p)
    {
        _Point vector   = VectMath.Subtract(p.Position, particle.Position);    //Vector pointing from particle to p
        double distance = VectMath.Magnitude(vector);

        if (distance > ParticleRadius & distance < AttractionRadius)
        {
            return(VectMath.Scale(vector, (1 / distance)));
        }
        else
        {
            if (distance < ParticleRadius)
            {
                if (distance == 0)
                {
                    return(new _Point(0, 0, 0));
                }
                else
                {
                    return(VectMath.Scale(vector, (-1 / distance)));
                }
            }
            else
            {
                return(new _Point(0, 0, 0));
            }
        }
    }
Пример #2
0
    public static _Point RotateByAngle(_Point pnt, _Point Axis, double Angle)
    {
        if (VectMath.IsParallel(pnt, Axis) == true)
        {
            return(pnt);
        }
        Angle = (Angle * Math.PI) / 180;
        _Point Avector     = VectMath.Subtract(pnt, VectMath.Project(pnt, Axis));
        double MagAvector  = VectMath.Magnitude(Avector);
        _Point V1          = VectMath.Unit(VectMath.Cross(Axis, Avector));
        _Point V2          = (VectMath.Negate(Avector));
        _Point TransVector = VectMath.Add(VectMath.Scale(V1, MagAvector * Math.Sin(Angle)), VectMath.Scale(V2, (-1 * Math.Cos(Angle) + 1)));

        return(VectMath.Add(TransVector, pnt));
    }
Пример #3
0
 public void Iterrate()
 {
     foreach (Particle particle in Particles)
     {
         particle.force = new _Point(0, 0, 0);
         foreach (Particle p in Particles)
         {
             particle.force = VectMath.Add(ForceOn(particle, p), particle.force);
         }
         particle.velocity = VectMath.Add(particle.velocity, (VectMath.Scale(VectMath.Scale(particle.force, 1 / particle.Mass), TimeInterval)));
         //MessageBox.Show(VectMath.Magnitude(particle.force).ToString());
     }
     foreach (Particle particle in Particles)
     {
         particle.Position = VectMath.Add(particle.Position, VectMath.Scale(particle.velocity, TimeInterval));
     }
 }
Пример #4
0
 public static _Point Unit(_Point a)
 {
     return(VectMath.Scale(a, 1 / VectMath.Magnitude(a)));
 }
Пример #5
0
 public static _Point Project(_Point a, _Point b)
 {
     return(VectMath.Scale(b, (VectMath.Dot(a, b) / (VectMath.SqrMagnitude(b)))));
 }