Example #1
0
        static public PVector random2D(PVector target = null)
        {
            double angle = (_rand.NextDouble() * Math.PI * 2);

            if (target == null)
            {
                target = new PVector(Math.Cos(angle), Math.Sin(angle), 0);
            }
            else
            {
                target.set(Math.Cos(angle), Math.Sin(angle), 0);
            }

            return(target);
        }
Example #2
0
        public PVector cross(PVector v, PVector target)
        {
            double crossX = y * v.z - v.y * z;
            double crossY = z * v.x - v.z * x;
            double crossZ = x * v.y - v.x * y;

            if (target == null)
            {
                target = new PVector(crossX, crossY, crossZ);
            }
            else
            {
                target.set(crossX, crossY, crossZ);
            }

            return(target);
        }
Example #3
0
        static public PVector cross(PVector v1, PVector v2, PVector target)
        {
            double crossX = v1.y * v2.z - v2.y * v1.z;
            double crossY = v1.z * v2.x - v2.z * v1.x;
            double crossZ = v1.x * v2.y - v2.x * v1.y;

            if (target == null)
            {
                target = new PVector(crossX, crossY, crossZ);
            }
            else
            {
                target.set(crossX, crossY, crossZ);
            }

            return(target);
        }
Example #4
0
        public PVector normalize(PVector target)
        {
            if (target == null)
            {
                target = new PVector();
            }
            double m = mag();

            if (m > 0)
            {
                target.set(x / m, y / m, z / m);
            }
            else
            {
                target.set(x, y, z);
            }
            return(target);
        }
Example #5
0
        static public PVector random3D(PVector target = null)
        {
            double angle;
            double vz;

            angle = (_rand.NextDouble() * Math.PI * 2);
            vz    = (_rand.NextDouble() * 2 - 1);

            double vx = (Math.Sqrt(1 - vz * vz) * Math.Cos(angle));
            double vy = (Math.Sqrt(1 - vz * vz) * Math.Sin(angle));

            if (target == null)
            {
                target = new PVector(vx, vy, vz);
                //target.normalize(); // Should be unnecessary
            }
            else
            {
                target.set(vx, vy, vz);
            }

            return(target);
        }
Example #6
0
 public PVector setMag(PVector target, double len)
 {
     target = normalize(target);
     target.mult(len);
     return(target);
 }
Example #7
0
 static public double dot(PVector v1, PVector v2)
 {
     return(v1.x * v2.x + v1.y * v2.y + v1.z * v2.z);
 }
Example #8
0
 public PVector cross(PVector v)
 {
     return(cross(v, null));
 }
Example #9
0
 public double dot(PVector v)
 {
     return(x * v.x + y * v.y + z * v.z);
 }
Example #10
0
 static public PVector div(PVector v, double n)
 {
     return(div(v, n, null));
 }
Example #11
0
 static public PVector mult(PVector v, double n)
 {
     return(mult(v, n, null));
 }
Example #12
0
 static public PVector sub(PVector v1, PVector v2)
 {
     return(sub(v1, v2, null));
 }
Example #13
0
 static public PVector add(PVector v1, PVector v2)
 {
     return(add(v1, v2, null));
 }