Пример #1
0
 public static double Distance(Vector v1, Vector v2)
 {
     double deltaX = v1.x - v2.x;
     double deltaY = v1.y - v2.y;
     double deltaZ = v1.z - v2.z;
     return Math.Sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
 }
Пример #2
0
 public void TestVectorPlus()
 {
     Vector v1 = new Vector(1, 2, 3);
     Vector v2 = new Vector(3, 2, 1);
     Vector result = v1 + v2;
     Vector expect = new Vector(4, 4, 4);
     Assert.AreEqual(expect, result);
 }
Пример #3
0
 public void TestVectorMinusSubstitute()
 {
     Vector v1 = new Vector(5, 4, 3);
     Vector v2 = new Vector(3, 2, 1);
     v1 -= v2;
     Vector expect = new Vector(2, 2, 2);
     Assert.AreEqual(expect, v1);
 }
Пример #4
0
 public void TestVectorMinus()
 {
     Vector v1 = new Vector(5, 4, 3);
     Vector v2 = new Vector(3, 2, 1);
     Vector result = v1 - v2;
     Vector expect = new Vector(2, 2, 2);
     Assert.AreEqual(expect, result);
 }
Пример #5
0
 public void TestVectorMag()
 {
     Vector v1 = new Vector(0, 3, 4);
     double result = LinearUtil.VectorMag(v1);
     Assert.AreEqual(5, result);
 }
Пример #6
0
 public void TestVectorDotProduct()
 {
     Vector v1 = new Vector(1, 2, 3);
     Vector v2 = new Vector(3, 2, 1);
     double result = v1 * v2;
     Assert.AreEqual(10, result);
 }
Пример #7
0
 public void TestVectorProductSubstitute()
 {
     Vector v1 = new Vector(1, 2, 3);
     v1 *= 3;
     Vector expect = new Vector(3, 6, 9);
     Assert.AreEqual(expect, v1);
 }
Пример #8
0
 public void TestNormarize()
 {
     Vector vector = new Vector(12, -5, 0);
     vector.Normalize();
     // Vector answer = new Vector(0.923, -0.385, 0);
     // Assert.AreEqual(answer, vector);
     Assert.AreEqual(0.923, Math.Round(vector.x, 3));
     Assert.AreEqual(-0.385, Math.Round(vector.y, 3));
     Assert.AreEqual(0, vector.z);
 }
Пример #9
0
 public void TestVectorDivByScalar()
 {
     Vector v1 = new Vector(27, 18, 9);
     Vector result = v1 / 3;
     Vector expect = new Vector(9, 6, 3);
     Assert.AreEqual(expect, result);
 }
Пример #10
0
 public void TestDistance()
 {
     Vector v1 = new Vector(5, 0, 0);
     Vector v2 = new Vector(-1, 8, 0);
     double result = LinearUtil.Distance(v1, v2);
     Assert.AreEqual(10, result);
 }
Пример #11
0
 public void TestIndexer()
 {
     double[] src = new double[]{0, 1, 2};
     Vector v1 = new Vector(src);
     Assert.AreEqual(0, v1[0]);
     Assert.AreEqual(1, v1[1]);
     Assert.AreEqual(2, v1[2]);
 }
Пример #12
0
 public void TestCrossProduct()
 {
     Vector v1 = new Vector(1, 3, 4);
     Vector v2 = new Vector(2, -5, 8);
     Vector result = LinearUtil.CrossProduct(v1, v2);
     Assert.AreEqual(new Vector(44, 0, -11), result);
 }
Пример #13
0
 private static Vector Product(Vector v1, double scalar)
 {
     return new Vector(v1.x * scalar, v1.y * scalar, v1.z * scalar);
 }
Пример #14
0
 public static double VectorMag(Vector v)
 {
     return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
 }
Пример #15
0
 public void TestVectorPlusSubstitute()
 {
     Vector v1 = new Vector(1, 2, 3);
     Vector v2 = new Vector(3, 2, 1);
     v1 += v2;
     Vector expect = new Vector(4, 4, 4);
     Assert.AreEqual(expect, v1);
 }
Пример #16
0
 public void TestVectorDivByZero()
 {
     Vector v1 = new Vector(27, 18, 9);
     Console.WriteLine(v1 / 0);
 }
Пример #17
0
 public void TestVectorProductByScalar()
 {
     Vector v1 = new Vector(1, 2, 3);
     Vector result = v1 * 3;
     Vector result2 = 3 * v1;
     Vector expect = new Vector(3, 6, 9);
     Assert.AreEqual(expect, result);
     Assert.AreEqual(expect, result2);
 }
Пример #18
0
 public void TestVectorDivSubstitute()
 {
     Vector v1 = new Vector(27, 18, 9);
     v1 /= 3;
     Vector expect = new Vector(9, 6, 3);
     Assert.AreEqual(expect, v1);
 }
Пример #19
0
 public void TestVectorTurnOver()
 {
     Vector v1 = new Vector(1, 1, 1);
     Vector result = -v1;
     Vector expect = new Vector(-1, -1, -1);
     Assert.AreEqual(expect, result);
 }
Пример #20
0
 public static Vector CrossProduct(Vector v1, Vector v2)
 {
     return new Vector(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, 	v1.x * v2.y - v1.y * v2.x);
 }