public override string ToString() { Vektor temp = new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = this.Finish.X - this.Start.X, Y = this.Finish.Y - this.Start.Y } }; return("{" + this.Finish.X + ", " + this.Finish.Y + "}"); }
/// <summary> /// Різниця векторів /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <returns></returns> public static Vektor operator -(Vektor a, Vektor b) { Vektor vA = new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = a.Finish.X - a.Start.X, Y = a.Finish.Y - a.Start.Y } }; Vektor vB = new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = b.Finish.X - b.Start.X, Y = b.Finish.Y - b.Start.Y } }; return(new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = vA.Finish.X - vB.Finish.X, Y = vA.Finish.Y - vB.Finish.Y } }); }
static void Main() { // Join Unicode Console.OutputEncoding = Encoding.Unicode; // створення веторів Vektor v1 = new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = 1, Y = 2 } }; Vektor v2 = new Vektor() { Start = new Point() { X = 0, Y = 0 }, Finish = new Point() { X = 4, Y = 8 } }; // вивід Console.WriteLine("\n\tv1 = " + v1.ToString()); Console.WriteLine("\tv2 = " + v2.ToString()); Console.WriteLine("\n\tv1 + v2 = " + (v1 + v2).ToString()); Console.WriteLine("\tv1 - v2 = " + (v1 - v2).ToString()); // repeat DoExitOrRepeat(); }