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); }
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); }
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); }
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); }
public void TestVectorMag() { Vector v1 = new Vector(0, 3, 4); double result = LinearUtil.VectorMag(v1); Assert.AreEqual(5, result); }
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); }
public void TestVectorProductSubstitute() { Vector v1 = new Vector(1, 2, 3); v1 *= 3; Vector expect = new Vector(3, 6, 9); Assert.AreEqual(expect, v1); }
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); }
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); }
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); }
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]); }
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); }
private static Vector Product(Vector v1, double scalar) { return new Vector(v1.x * scalar, v1.y * scalar, v1.z * scalar); }
public static double VectorMag(Vector v) { return Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z); }
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); }
public void TestVectorDivByZero() { Vector v1 = new Vector(27, 18, 9); Console.WriteLine(v1 / 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); }
public void TestVectorDivSubstitute() { Vector v1 = new Vector(27, 18, 9); v1 /= 3; Vector expect = new Vector(9, 6, 3); Assert.AreEqual(expect, v1); }
public void TestVectorTurnOver() { Vector v1 = new Vector(1, 1, 1); Vector result = -v1; Vector expect = new Vector(-1, -1, -1); Assert.AreEqual(expect, result); }
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); }