public static Figure GetRotatedFigure(Figure figure, double angleOfRotationInRadians) { double cosOfAngle = Math.Cos(angleOfRotationInRadians); double sinOfAngle = Math.Sin(angleOfRotationInRadians); double rotatedWidth = (Math.Abs(cosOfAngle) * figure.Width) + (Math.Abs(sinOfAngle) * figure.Height); double rotatedHeight = (Math.Abs(sinOfAngle) * figure.Width) + (Math.Abs(cosOfAngle) * figure.Height); return new Figure(rotatedWidth, rotatedHeight); }
public static void Main() { Figure rectangle = new Figure(10, 20); Figure rotatedRectangle = FigureRotator.GetRotatedFigure(rectangle, 2); Console.WriteLine("Rotated figure width: {0} and height: {1}", rotatedRectangle.Width, rotatedRectangle.Height); }