public Vector(Vector v) { coords = new double[v.coords.Length]; for (int i = 0; i < v.coords.Length; i++) { coords[i] = v.coords[i]; } }
static void Main(string[] args) { Point p1 = new Point(1.2, 2.1); Point p2 = new Point(5.4, 7.2); Console.WriteLine("{0} + {1} = {2}", p1, p2, p1 + p2); Console.WriteLine(); LineSegment ls1 = new LineSegment(new Point(1, 1), new Point(1, 5)); LineSegment ls2 = new LineSegment(new Point(2, 3), new Point(4, 5)); Console.WriteLine("{0} -> Length: {1}", ls1, ls1.GetLength()); Console.WriteLine("{0} -> Length: {1}", ls2, ls2.GetLength()); Console.WriteLine(); Rectangle rect = new Rectangle(p1, p2); Rectangle rect2 = new Rectangle(p2, p1); Console.WriteLine("Is {0} equal to {1} -> {2}", rect, rect2, rect.Equals(rect2)); Console.WriteLine(); Console.WriteLine("Rectangle from {0} and {1} has these properties:", p1, p2); Console.WriteLine("Width: {0}", rect.Width); Console.WriteLine("Height: {0}", rect.Height); Console.WriteLine("Lower Left: {0}", rect.LowerLeftPoint); Console.WriteLine("Lower Rigth: {0}", rect.LowerRightPoint); Console.WriteLine("Upper Left: {0}", rect.UpperLeftPoint); Console.WriteLine("Upper Rigth: {0}", rect.UpperRightPoint); Console.WriteLine("Perimeter: {0}", rect.GetPerimeter()); Console.WriteLine("Area: {0}", rect.GetArea()); Console.WriteLine("Center: {0}", rect.Center); Console.WriteLine(); Vector v1 = new Vector(1, 2, 3, 4); Vector v2 = new Vector(7, 3, 8, 1); Console.WriteLine("{0} + {1} = {2}", v1, v2, v1 + v2); Console.WriteLine("{0} - {1} = {2}", v1, v2, v1 - v2); Console.WriteLine("{0} * {1} = {2}", v1, v2, v1 * v2); Console.WriteLine("{0} - {1} = {2}", v1, 0.2, v1 - 0.2); Console.WriteLine("{0} * {1} = {2}", v1, 0.2, v1 * 0.2); Console.ReadKey(); }
/// <summary> /// Main Method. /// </summary> public static void Main() { Point point = new Point(0, 0); Point point2 = new Point(4, 4); Point point3 = new Point(5, 5); Point point4 = new Point(1, 1); LineSegment line = new LineSegment(point, point2); LineSegment line2 = new LineSegment(point3, point4); Rectangle rect = new Rectangle(point, point2); Rectangle rect2 = new Rectangle(point3, point4); // TODO : properties for edges; Vector vect1 = new Vector(1, 2, 3); Vector vect2 = new Vector(4, 5, 6); Console.WriteLine(vect1 * vect2); }
static void Main(string[] args) { Point firstPoint = new Point(5, 5); Point secondPoint = new Point(7, 7); LineSegment first = new LineSegment(firstPoint, secondPoint); LineSegment second = new LineSegment(firstPoint, secondPoint); Console.WriteLine(first > second); Console.WriteLine(first >= second); Console.WriteLine(first == second); LineSegment twoPoints = firstPoint + secondPoint; Rectangle rect = new Rectangle(firstPoint, secondPoint); Rectangle anotherRect = new Rectangle(secondPoint, firstPoint); Console.WriteLine("Equals: " + rect.Equals(anotherRect)); Console.WriteLine(); Console.WriteLine("Width: {0}", rect.GetWidth); Console.WriteLine("Height: {0}", rect.GetHeight); Console.WriteLine("Lower Left: {0}", rect.GetLowerLeftPoint); Console.WriteLine("Lower Rigth: {0}", rect.GetLowerRightPoint); Console.WriteLine("Upper Left: {0}", rect.GetUpperLeftPoint); Console.WriteLine("Upper Rigth: {0}", rect.GetUpperRightPoint); Console.WriteLine("Perimeter: {0}", rect.GetPerimeter()); Console.WriteLine("Area: {0}", rect.GetArea()); Console.WriteLine("Center: {0}", rect.GetCenterPoint); Console.WriteLine(); Vector vector = new Vector(new double[] { 1, 2, 3, 4 }); Vector anotherVector = new Vector(new double[] { 5, 6, 7, 8, 9 }); Console.WriteLine("{0} + {1} = {2}", vector, anotherVector, vector + anotherVector); Console.WriteLine("{0} - {1} = {2}", vector, anotherVector, vector - anotherVector); Console.WriteLine("{0} * {1} = {2}", vector, anotherVector, vector * anotherVector); double scalar = 0.7; Console.WriteLine("{0} - {1} = {2}", vector, scalar, vector - scalar); Console.WriteLine("{0} * {1} = {2}", vector, scalar, vector * scalar); Console.WriteLine(); }
/// <summary> /// Initializes a new instance of the <see cref="Vector"/> class. Copy Constructor. /// </summary> /// <param name="vect">Vector object to copy.</param> public Vector(Vector vect) { this.coordinates = vect.coordinates; }
/// <summary> /// Operator / for a Vector object and a double. /// </summary> /// <param name="vect1">Vector object.</param> /// <param name="scal">double number.</param> /// <returns>The division of the Vector object and the double.</returns> public static Vector operator /(Vector vect1, double scal) { Vector result = new Vector(); for (int i = 0; i < vect1.coordinates.Count; i++) { result[i] = vect1.coordinates[i] / scal; } return result; }