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