public Cartesian2DVector Subtract(Cartesian2DVector vector1, Cartesian2DVector vector2) { var vec = new Cartesian2DVector(); vec.X = vector1.X - vector2.X; vec.Y = vector1.Y - vector2.Y; return vec; }
public Cartesian2DVector Add(Cartesian2DVector vector1, Cartesian2DVector vector2) { var vec = new Cartesian2DVector(); vec.X = vector1.X + vector2.X; vec.Y = vector1.Y + vector2.Y; return vec; }
public Cartesian2DVector Scale(Cartesian2DVector vector, int factor) { var vec = new Cartesian2DVector(); vec.X = vector.X * factor; vec.Y = vector.Y * factor; return vec; }
public void TestScaleVector() { var vector = new Cartesian2DVector { X = 5, Y = 3 }; var calc = new VectorCalculator(); int factor = 5; var result = calc.Scale(vector, factor); Assert.That(result.X, Is.EqualTo(25)); Assert.That(result.Y, Is.EqualTo(15)); }
public void TestSubtractTwoVectors() { Cartesian2DVector vector1 = new Cartesian2DVector { X = 5, Y = 10 }; Cartesian2DVector vector2 = new Cartesian2DVector { X = 3, Y = 14 }; var calc = new VectorCalculator(); Cartesian2DVector result = calc.Subtract(vector1, vector2); Assert.That(result.X, Is.EqualTo(2)); Assert.That(result.Y, Is.EqualTo(-4)); }
public void TestDotProduct() { var vector1 = new Cartesian2DVector { X = 5, Y = 7 }; var vector2 = new Cartesian2DVector { X = 3, Y = 2 }; var calc = new VectorCalculator(); int result = calc.DotProduct(vector1, vector2); Assert.That(result, Is.EqualTo(29)); }
public void TestAddTwoVectors() { Cartesian2DVector vector1 = new Cartesian2DVector { X = 5, Y = 10 }; Cartesian2DVector vector2 = new Cartesian2DVector { X = 3, Y = 14 }; VectorCalculator calc = new VectorCalculator(); Cartesian2DVector result = calc.Add(vector1, vector2); Assert.That(result.X, Is.EqualTo(8)); Assert.That(result.Y, Is.EqualTo(24)); }
public double Magnitude(Cartesian2DVector vector) { return Math.Sqrt(Math.Pow(vector.X, 2) + Math.Pow(vector.Y, 2)); }
public int DotProduct(Cartesian2DVector vector1, Cartesian2DVector vector2) { return (vector1.X * vector2.X) + (vector1.Y * vector2.Y); }
public void TestVectorMagnitude() { var vector = new Cartesian2DVector { X = 3, Y = 5 }; var calc = new VectorCalculator(); double result = calc.Magnitude(vector); Assert.That(result, Is.EqualTo(Math.Sqrt(vector.X * vector.X + vector.Y * vector.Y))); }