Example #1
0
        /// <summary>
        /// Rotates instance of class Size.
        /// </summary>
        /// <param name="size">Type size.</param>
        /// <param name="angle">An angle, measured in radians.</param>
        /// <returns>Returns new instance of Size, the result after rotation.</returns>
        public static Size GetRotatedSize(Size size, double angle)
        {
            var newWidth = Math.Abs(Math.Cos(angle) * size.Width) + Math.Abs(Math.Sin(angle) * size.Height);
            var newHeigth = Math.Abs(Math.Sin(angle) * size.Width) + Math.Abs(Math.Cos(angle) * size.Height);

            return new Size(newWidth, newHeigth);
        }
        public static Size GetRotatedSize(Size figure, double angle)
        {
            double sinOfTheAngle = Math.Abs(Math.Sin(angle));
            double cosOfTheAngle = Math.Abs(Math.Sin(angle));

            double newWidth = (cosOfTheAngle * figure.width) + (sinOfTheAngle * figure.height);
            double newHeight = (sinOfTheAngle * figure.width) + (cosOfTheAngle * figure.height);

            return new Size(newWidth, newHeight);
        }
Example #3
0
 private static void Main()
 {
     const double fortyFiveDegreesInRadians = 0.7853981634;
     var figure = new Size(10, 10);
     Console.WriteLine("Sizes before rotation: width: {0:0.00}, height: {1:0.00}", figure.Width, figure.Height);
     var rotatedFigure = Size.GetRotatedSize(figure, fortyFiveDegreesInRadians);
     Console.WriteLine("Sizes after first rotation on 45 degrees: width: {0:0.00}, height: {1:0.00}", rotatedFigure.Width, rotatedFigure.Height);
     rotatedFigure = Size.GetRotatedSize(rotatedFigure, fortyFiveDegreesInRadians);
     Console.WriteLine("Sizes after second rotation on 45 degrees: {0:0.00}, height: {1:0.00}", rotatedFigure.Width, rotatedFigure.Height);
 }
        /// <summary>
        /// The method calculates the new size after of rotation by N degrees
        /// </summary>
        /// http://www.willperone.net/Code/coderr.php
        public static Size GetRotatedSize(Size size, double figureAngle)
        {
            double dimensionCos = Math.Abs(Math.Cos(figureAngle)) * size.Width;
            double dimensionSin = Math.Abs(Math.Sin(figureAngle)) * size.Height;

            double width = dimensionCos + dimensionSin;
            double height = dimensionCos + dimensionSin;

            return new Size(width, height);
        }
Example #5
0
        public static Size GetRotatedSize(Size figure, double angleOfRotation)
        {
            double angleOfRotationCos = Math.Cos(angleOfRotation);
            double angleOfRotationSin = Math.Cos(angleOfRotation);

            double newWidth = Math.Abs(angleOfRotationCos) * figure.width + Math.Abs(angleOfRotationSin) * figure.height;
            double newHeight = Math.Abs(angleOfRotationSin) * figure.width + Math.Abs(angleOfRotationCos) * figure.height;

            return new Size(newWidth, newHeight);
        }
Example #6
0
        public static Size GetRotatedSize(
            Size size, double angleOfRotation)
        {
            double sinusTimesWidth = Math.Abs(Math.Sin(angleOfRotation) * size.Width);
            double cosinusTimesWidth = Math.Abs(Math.Cos(angleOfRotation) * size.Width);
            double sinusTimesHeight = Math.Abs(Math.Sin(angleOfRotation) * size.Height);
            double cosinusTimesHeigth = Math.Abs(Math.Cos(angleOfRotation) * size.Height);

            double rotatedFigureWidth = cosinusTimesWidth + sinusTimesHeight;
            double rotatedFigureHeight = sinusTimesWidth + cosinusTimesHeigth;

            Size rotatedFigure = new Size(rotatedFigureWidth, rotatedFigureHeight);

            return rotatedFigure;
        }
Example #7
0
        /// <summary>
        /// Find rotated size with given size of figure and angle of rotation.
        /// </summary>
        /// <param name="figureSize">Size of figure.</param>
        /// <param name="rotationAngle">Angle of rotation.</param>
        /// <returns>Rotated size.</returns>
        public static Size GetRotatedSize(Size figureSize, double rotationAngle)
        {
            var rotationAngleCos = Math.Cos(rotationAngle);
            var rotationAngleSin = Math.Sin(rotationAngle);

            var moduleCosAngle = Math.Abs(rotationAngleCos);
            var moduleSinAngle = Math.Abs(rotationAngleSin);

            var rotatedCosWidth = moduleCosAngle*figureSize.Width;
            var rotatedCosHeight = moduleCosAngle * figureSize.Height;
            var rotatedSinHeight = moduleSinAngle*figureSize.Height;
            var rotatedSinWidth = moduleSinAngle*figureSize.Width;

            var rotatedWidth = rotatedCosWidth + rotatedSinHeight;
            var rotatedHeight = rotatedSinWidth + rotatedCosHeight;

            var rotatedSize = new Size(rotatedWidth, rotatedHeight);

            return rotatedSize;
        }