示例#1
0
        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;
        }
示例#2
0
        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;
        }
示例#3
0
        public Cartesian2DVector Scale(Cartesian2DVector vector, int factor)
        {
            var vec = new Cartesian2DVector();
            vec.X = vector.X * factor;
            vec.Y = vector.Y * factor;

            return vec;
        }
示例#4
0
        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));
        }
示例#5
0
        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));
        }
示例#6
0
        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));
        }
示例#7
0
        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));
        }
示例#8
0
 public double Magnitude(Cartesian2DVector vector)
 {
     return Math.Sqrt(Math.Pow(vector.X, 2) + Math.Pow(vector.Y, 2));
 }
示例#9
0
 public int DotProduct(Cartesian2DVector vector1, Cartesian2DVector vector2)
 {
     return (vector1.X * vector2.X) + (vector1.Y * vector2.Y);
 }
示例#10
0
        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)));
        }