using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace cv4 { class Vector : IFormattable { public float x, y, z; public Vector(float x, float y, float z) { this.x = x; this.y = y; this.z = z; } public Vector() { x = y = z = 0; } public float Length() { return (float)Math.Pow(x * x + y * y + z * z, 0.5); } public Vector Unit() { float l = 1/Length(); return this* l; } public static Vector operator+( Vector a, Vector b) { return new Vector(a.x + b.x, a.y + b.y, a.z + b.z); } public static Vector operator-(Vector a, Vector b) { return new Vector(a.x - b.x, a.y - b.y, a.z - b.z); } public static Vector operator*(Vector a, float b) { return new Vector(a.x * b, a.y * b, a.z * b); } public static Vector operator *(float b, Vector a) { return a * b; } public static Vector operator |(Vector a, float c) { return c * a.Unit(); } public static float operator%(Vector a,Vector b) { return a.x * b.x + a.y * b.y + a.z * b.z; } public static Vector operator ^(Vector a, Vector b) { return new Vector(a.y * b.z - a.z * b.y, a.x * b.z - a.z * b.x, a.x * b.y - a.y * b.x); } public string ToString(string format, IFormatProvider provider) { return "(" + x + ", " + y + ", " + z + ")"; } } class Program { static void Main(string[] args) { float step = 0.00001f; Vector rychlost = new Vector(1,0,1); Vector pozice = new Vector(); Vector gravitace = new Vector(0,0,-9.81f); rychlost = rychlost | 500; float dur = 0; float odpor = 0.99f; Vector vietor = new Vector(20, 20, 0); for (; pozice.z >= 0; dur += step) { pozice += rychlost * step; rychlost += gravitace * step; rychlost -= vietor; rychlost *= (float)Math.Pow(odpor, step); rychlost += vietor; } Console.WriteLine(pozice); Console.WriteLine("sim trvala {0}", dur); /*Vector a = new Vector(1, 1, 0); Vector b = new Vector(1, -1, 0); Vector c = a^b; //Console.WriteLine("({0}, {1}, {2})", c.x, c.y, c.z); Console.WriteLine(c);*/ } } }