Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Type Realization = EnterRealization();

            IVector3f current = EnterVector(Realization);

            int answer;

            do
            {
                answer = Ask(
                    "What you want to do?",
                    new List <string> {
                    "Exit",
                    "Change realization",
                    "Enter new vector",
                    "Print current vector",
                    "Print lenth of current vector",
                    "Calculate sum with another vector",
                    "Calculate difference with another vector",
                    "Calculate dot product with another vector",
                    "Calculate cos between this and another vector",
                });

                IVector3f another = null;
                switch (answer)
                {
                case 0: return;

                case 1:
                    Realization = EnterRealization();
                    current     = (IVector3f)Activator.CreateInstance(Realization, current.X, current.Y, current.Z);
                    break;

                case 2: current = EnterVector(Realization); break;

                case 3: Console.WriteLine($"Current vector is {current.ToString()}"); break;

                case 4: Console.WriteLine($"Current vector's lenght is {current.Lenght()}"); break;

                case 5:
                    another = EnterVector(Realization);
                    Console.WriteLine($"Sum of vectors {current} and {another} is {current.Sum(another)} ");
                    break;

                case 6:
                    another = EnterVector(Realization);
                    Console.WriteLine($"Difference of vectors {current} and {another} is {current.Diff(another)} ");
                    break;

                case 7:
                    another = EnterVector(Realization);
                    Console.WriteLine($"Dot product of vectors {current} and {another} is {current.Dot(another)} ");
                    break;

                case 8:
                    another = EnterVector(Realization);
                    Console.WriteLine($"Cosine between vectors {current} and {another} is {current.Cos(another)} ");
                    break;

                default: Console.WriteLine("Wrong answer!"); break;
                }
            } while (answer != 0);
        }
Exemplo n.º 2
0
 public virtual float Cos(IVector3f other) => Dot(other) / (Lenght() * other.Lenght());
Exemplo n.º 3
0
 public virtual float Dot(IVector3f other) => X * other.X + Y * other.Y + Z * other.Z;
Exemplo n.º 4
0
 public virtual IVector3f Diff(IVector3f other) => new Vector3f(X - other.X, Y - other.Y, Z - other.Z);
Exemplo n.º 5
0
 public virtual IVector3f Sum(IVector3f other) => new Vector3f(X + other.X, Y + other.Y, Z + other.Z);
Exemplo n.º 6
0
 public override float Cos(IVector3f other)
 {
     Console.WriteLine("Overriden method {0} is called", System.Reflection.MethodBase.GetCurrentMethod().Name);
     return(base.Cos(other));
 }