static void Main(string[] args) { var rectangle = new Rectangle(5, 12); Console.WriteLine("Created rectangle with (Width: {0}, Height: {1}).", rectangle.Width, rectangle.Height); var rotatedRectangle = Rectangle.GetRotatedRectangle(rectangle, Math.PI / 2); // PI/2 is 90 degrees Console.WriteLine("Rotated rectangle(90 degrees) with (Width: {0}, Height: {1}).", rotatedRectangle.Width, rotatedRectangle.Height); }
public static Rectangle GetRotatedRectangle(Rectangle rectangle, double angleOfRotation) { //I don't understand the expression, but tried to simplify it and make it easier to read. double sinus = Math.Abs(Math.Sin(angleOfRotation)); double cosinus = Math.Abs(Math.Cos(angleOfRotation)); double width = cosinus * rectangle.Width + sinus * rectangle.Height; double height = sinus * rectangle.Width + cosinus * rectangle.Height; return new Rectangle(width, height); }
static void Main(string[] args) { //2c: int num1 = 1; int num2 = 2; int total = 0; total = num1 + num2; Console.WriteLine("{0} + {1} = {2}", num1, num2, total); //2d: Add(20, 30); //2e: Add(20, 30, 25); //2g: Rectangle rectangle = new Rectangle(); rectangle.RectangleArea(3, 5); //2h: rectangle.RectangleArea(4, 5); Console.ReadKey(); }