예제 #1
0
 public void CrossProduct()
 {
     Vector3D Test1 = new Vector3D(10, 0, 0);
     Vector3D Test2 = new Vector3D(1, 1, 0);
     Vector3D CrossResult = Test2.Cross(Test1);
     Assert.IsTrue(CrossResult.x == 0);
     Assert.IsTrue(CrossResult.y == 0);
     Assert.IsTrue(CrossResult.z < 0);
 }
예제 #2
0
        public void ScalarDivision()
        {
            Vector3D ScalarMultiplicationArgument = new Vector3D(5.0f, 4.0f, 3.0f);
            Assert.IsTrue(ScalarMultiplicationArgument / 2 == new Vector3D(2.5f, 2.0f, 1.5f));
            Assert.IsTrue(2 / ScalarMultiplicationArgument == new Vector3D(2.5f, 2.0f, 1.5f));

            Vector3D Point3 = new Vector3D(12, 18, 24);
            Point3 /= 6;
            Assert.IsTrue(Point3.Equals(new Vector3D(2, 3, 4), .01f));
        }
예제 #3
0
 public void DotProduct()
 {
     Vector3D Test1 = new Vector3D(10, 1, 2);
     Vector3D Test2 = new Vector3D(1, 0, 0);
     double DotResult = Test2.Dot(Test1);
     Assert.IsTrue(DotResult == 10);
 }
예제 #4
0
 public void EquLinComb(double r, Vector3D A, double s, Vector3D B)
 {
     // the two Vectors are muliplied by thier own variable scale and then added together
     x = r * A.x + s * B.x;
     y = r * A.y + s * B.y;
     z = r * A.z + s * B.z;
 }
예제 #5
0
        public void ScalarMultiplication()
        {
            Vector3D ScalarMultiplicationArgument = new Vector3D(5.0f, 4.0f, 3.0f);
	        Assert.IsTrue(ScalarMultiplicationArgument*-.5 == -new Vector3D(2.5f, 2.0f, 1.5f));
            Assert.IsTrue(-.5 * ScalarMultiplicationArgument == -new Vector3D(2.5f, 2.0f, 1.5f));
	        Assert.IsTrue(5*ScalarMultiplicationArgument == new Vector3D(25.0f, 20.0f, 15.0f));

            Vector3D Point3 = new Vector3D(2, 3, 4);
            Point3 *= 6;
            Assert.IsTrue(Point3.Equals(new Vector3D(12, 18, 24), .01f));
        }
예제 #6
0
 public void Set(Vector3D Src)
 {
     x = Src.x;
     y = Src.y;
     z = Src.z;
 }
예제 #7
0
 public void Cross(Vector3D A, Vector3D B)
 {
     x = A.y * B.z - A.z * B.y;
     y = A.z * B.x - A.x * B.z;
     z = A.x * B.y - A.y * B.x;
 }
예제 #8
0
 public void GetPerpendicularVector(Vector3D DestVector)
 {
     if (x == 0.0f)
     {
         DestVector.Set(1.0f, 0.0f, 0.0f);
     }
     else if (y == 0.0f)
     {
         DestVector.Set(0.0f, 1.0f, 0.0f);
     }
     else if (z == 0.0f)
     {
         DestVector.Set(0.0f, 0.0f, 1.0f);
     }
     else
     {
         // pick a vector perpendicular to our original vector
         // we want ConeDir . PerpVec == 0, so this gives us
         // -y/x * x + 1 * y + 0 * z ==
         // -y + y + 0 == 0
         //
         // so this vector is perpendicular to our original one
         if (System.Math.Abs(x) > System.Math.Abs(y))
         {
             if (System.Math.Abs(y) > System.Math.Abs(z))
             {
                 // x is the biggest z is the smallest
                 DestVector.Set(z / x, 0.0f, -1.0f);
             }
             else
             {
                 // x is the biggest y is the smallest
                 DestVector.Set(y / x, -1.0f, 0.0f);
             }
         }
         else if (System.Math.Abs(z) > System.Math.Abs(y)) // y > x
         {
             // z is the biggest x is the smallest
             DestVector.Set(-1.0f, 0.0f, x / z);
         }
         else // y > x && z < y
         {
             // y is the biggest
             if (x > z)
             {
                 // y is the biggest z is the smallest
                 DestVector.Set(0.0f, z / y, -1.0f);
             }
             else
             {
                 // y is the biggest x is the smallest
                 DestVector.Set(-1.0f, x / y, 0.0f);
             }
         }
     }
 }
예제 #9
0
 //Vector3D	 	operator-(Vector3D B);
 // this = pOne - pSubtracted
 public void Minus(Vector3D One, Vector3D Subtracted)
 {
     x = One.x - Subtracted.x;
     y = One.y - Subtracted.y;
     z = One.z - Subtracted.z;
 }
예제 #10
0
        public void EquMax(Vector3D VectorOne, Vector3D VectorTwo)
        {
            if (VectorOne.x > VectorTwo.x)
                x = VectorOne.x;
            else
                x = VectorTwo.x;

            if (VectorOne.y > VectorTwo.y)
                y = VectorOne.y;
            else
                y = VectorTwo.y;

            if (VectorOne.z > VectorTwo.z)
                z = VectorOne.z;
            else
                z = VectorTwo.z;
        }
예제 #11
0
        // are they the same within the error value?
        public bool Equals(Vector3D OtherVector, double ErrorValue)
        {
            if ((x < OtherVector.x + ErrorValue && x > OtherVector.x - ErrorValue) &&
                (y < OtherVector.y + ErrorValue && y > OtherVector.y - ErrorValue) &&
                (z < OtherVector.z + ErrorValue && z > OtherVector.z - ErrorValue))
            {
                return true;
            }

            return false;
        }
예제 #12
0
        public void EquMin(Vector3D VectorOne, Vector3D VectorTwo)
        {
            // set it equal to the min
            if (VectorOne.x < VectorTwo.x)
                x = VectorOne.x;
            else
                x = VectorTwo.x;

            if (VectorOne.y < VectorTwo.y)
                y = VectorOne.y;
            else
                y = VectorTwo.y;

            if (VectorOne.z < VectorTwo.z)
                z = VectorOne.z;
            else
                z = VectorTwo.z;
        }
예제 #13
0
 public void ScaleMult(double r, Vector3D VectorOne)
 {
     // The Vector3D is scaled and then multiplied by another Vector3D.
     x = r * x * VectorOne.x;
     y = r * y * VectorOne.y;
     z = r * z * VectorOne.z;
 }
예제 #14
0
 public void ScaleAdd(double r, Vector3D VectorOne)
 {
     // The Vector3D is scaled and then another Vector3D is added to it.
     x = r * x + VectorOne.x;
     y = r * y + VectorOne.y;
     z = r * z + VectorOne.z;
 }
예제 #15
0
 public void Normalize()
 {
     Vector3D Point3 = new Vector3D(3, -4, 5);
     Point3.Normalize();
     Assert.IsTrue(Point3.GetRadius() > 0.99 && Point3.GetRadius() < 1.01);
 }
예제 #16
0
 public void Plus(Vector3D One, Vector3D Two)
 {
     x = One.x + Two.x;
     y = One.y + Two.y;
     z = One.z + Two.z;
 }
예제 #17
0
 public void Rotate()
 {
     Vector3D Test = new Vector3D(0, 1, 0);
     Test.RotateAboutX(System.Math.PI / 2);
     Assert.IsTrue(Test.Equals(new Vector3D(0,0,1), 0.001f));
     Test.RotateAboutY(System.Math.PI / 2);
     Assert.IsTrue(Test.Equals(new Vector3D(1,0,0), 0.001f));
     Test.RotateAboutZ(System.Math.PI / 2);
     Assert.IsTrue(Test.Equals(new Vector3D(0, 1, 0), 0.001f));
 }
예제 #18
0
 public Vector3D(Vector3D vector3D)
 {
     x = vector3D.x;
     y = vector3D.y;
     z = vector3D.z;
 }
예제 #19
0
 public double Dot(Vector3D B)
 {
     return (x * B.x + y * B.y + z * B.z);
 }
예제 #20
0
        public void VectorAdditionAndSubtraction()
        {
            Vector3D Point1 = new Vector3D();
            Point1.Set(1, 1, 1);

            Vector3D Point2 = new Vector3D();
            Point2.Set(2, 2, 2);

            Vector3D Point3 = new Vector3D();
            Point3.Plus(Point1, Point2);
            Assert.IsTrue(Point3 == new Vector3D(3, 3, 3));

            Point3.Minus(Point1, Point2);
            Assert.IsTrue(Point3 == new Vector3D(-1, -1, -1));

            Point3 += Point1;
            Assert.IsTrue(Point3 == new Vector3D(0, 0, 0));

            Point3 += Point2;
            Assert.IsTrue(Point3 == new Vector3D(2, 2, 2));

            Point3.Set(3, -4, 5);
            Assert.IsTrue(Point3.GetRadius() > 7.07 && Point3.GetRadius() < 7.08);

            Vector3D InlineOpLeftSide = new Vector3D(5.0f, -3.0f, .0f);
            Vector3D InlineOpRightSide = new Vector3D(-5.0f, 4.0f, 1.0f);
            Assert.IsTrue(InlineOpLeftSide + InlineOpRightSide == new Vector3D(.0f, 1.0f, 1.0f));

            Assert.IsTrue(InlineOpLeftSide - InlineOpRightSide == new Vector3D(10.0f, -7.0f, -1.0f));
        }
예제 #21
0
        public void DotProduct()
        {
            Random Rand = new Random();
            Vector2D TestVector2D1 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            Vector2D TestVector2D2 = new Vector2D(Rand.NextDouble() * 1000, Rand.NextDouble() * 1000);
            double Cross2D = TestVector2D1.Dot(TestVector2D2);

            Vector3D TestVector3D1 = new Vector3D(TestVector2D1.x, TestVector2D1.y, 0);
            Vector3D TestVector3D2 = new Vector3D(TestVector2D2.x, TestVector2D2.y, 0);
            double Cross3D = TestVector3D1.Dot(TestVector3D2);

            Assert.IsTrue(Cross3D == Cross2D);
        }
예제 #22
0
 public Vector3D Cross(Vector3D B)
 {
     Vector3D Temp = new Vector3D();
     Temp.Cross(this, B);
     return Temp;
 }