예제 #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 static _Point Unit(_Point a)
 {
     return(VectMath.Scale(a, 1 / VectMath.Magnitude(a)));
 }
예제 #4
0
 public static double AngleBetween(_Point a, _Point b)
 {
     return(Math.Acos((VectMath.Dot(a, b)) / (VectMath.Magnitude(a) * VectMath.Magnitude(b))));
 }