コード例 #1
0
ファイル: Figure.cs プロジェクト: jesconsa/Telerik-Academy
        /// <summary>
        /// Rotate figure by given angle of rotation
        /// </summary>
        /// <param name="figure">The figure to rotate</param>
        /// <param name="rotationAngle">The angle of rotation</param>
        /// <returns>A new figure after rotation by the given angle of rotation</returns>
        public static Figure Rotate(Figure figure, double rotationAngle)
        {
            var sinValue = Math.Abs(Math.Sin(rotationAngle));
            var cosValue = Math.Abs(Math.Cos(rotationAngle));

            var newWidth = cosValue * figure.Width + sinValue * figure.Height;
            var newHeight = sinValue * figure.Width + cosValue * figure.Height;

            Figure rotatedFigure = new Figure(newWidth, newHeight);

            return rotatedFigure;
        }
コード例 #2
0
        static void Main()
        {
            var width = 25.23;
            var height = 2.12;
            var figure = new Figure(width, height);

            Console.WriteLine(figure);

            var angleOfRotation = -180;
            var rotatedFigure = Figure.Rotate(figure, angleOfRotation);
            Console.WriteLine(rotatedFigure);
        }