예제 #1
0
        static void Main(string[] args)
        {
            Vector2D vec1 = new Vector2D(1.0, 3.0);
            Vector2D vec2 = new Vector2D(2.0, 4.0);
            Vector2D vec3 = new Vector2D(1.0, 3.0);
            Vector2D vec4 = new Vector2D(3.0, 1.0);
            Matrix2x2 m = new Matrix2x2(vec1, vec2);
            Matrix2x2 n = new Matrix2x2(vec3, vec4);
            Matrix2x2 p;

            Console.WriteLine("m is");

            m.WriteMatrix();

            Console.WriteLine("n is");

            n.WriteMatrix();

            Console.WriteLine("Transpose matrix m");

            m.Transpose();
            m.WriteMatrix();

            Console.WriteLine("Add matrix m and n");

            m.AddMatrix(n);
            m.WriteMatrix();

            Console.WriteLine("subtract matrix m-n");
            m.SubtractMatrix(n);
            m.WriteMatrix();

            Console.WriteLine("Multiply m and n");

            p = m.MultiplyMatrix(n);
            p.WriteMatrix();

            m.SetScalingMatrix(4, 4);
            m.WriteMatrix();

            m.SetRotationMatrixInDegrees(60.0);
            m.WriteMatrix();

            m.SetIdentityMatrix();
            m.WriteMatrix();

            Console.ReadLine();
        }
예제 #2
0
 //Gets the dot product of two Vector2D objects
 public double GetDotProduct(Vector2D otherVector)
 {
     return ((X * otherVector.X) + (Y * otherVector.Y));
 }
예제 #3
0
 //Gets the angle between two Vector2D objects in radians
 public double GetAngleBetweenVector(Vector2D otherVector)
 {
     return Math.Acos(GetDotProduct(otherVector) / (GetMagnitude() * otherVector.GetMagnitude()));
 }
예제 #4
0
 //Finds the linear interpolation Vector2D between two Vector2D objects
 //Using t, to determine the position of the linear interpolation vector is oriented between the two Vector2D objects
 //t=0 LerpVector = Vector2D being used to call the method Lerp(otherVector,t) , t=1 LerpVector = otherVector
 public void Lerp(Vector2D otherVector, double t)
 {
     //0 <=  t <= 1
     //New vector = (1 - t)A + tB
     //A-tA + tB
     if(0 <= t && t <= 1)
     {
         Vector2D scaledVA = new Vector2D(X, Y);
         Vector2D scaledVB = new Vector2D(otherVector.X, otherVector.Y);
         scaledVA.ScalarMultiplication(t);
         scaledVB.ScalarMultiplication(t);
         SubtractVector(scaledVA.X, scaledVA.Y);
         AddVector(scaledVB.X, scaledVB.Y);
     }
     else
     {
         Console.WriteLine("Invalid value for t");
     }
 }