/// <summary>
        /// Rotates a rectangle around a coordinate
        /// </summary>
        /// <param name="rectangle">The rectangle to apply the rotation</param>
        /// <param name="angle">The clockwise angle of the rotation</param>
        /// <returns>The minimum bounding rectangle (MBR) of the rotated rectangle</returns>
        public static RectangleF RotateAt(RectangleF rectangle, float angle, PointF center)
        {
            // The graphics transform method only accepts arrays :P
            PointF[] points = new PointF[4]
            {
                new PointF(rectangle.Left, rectangle.Top),
                new PointF(rectangle.Right, rectangle.Top),
                new PointF(rectangle.Right, rectangle.Bottom),
                new PointF(rectangle.Left, rectangle.Bottom)
            };

            Matrix rotationMatrix = new Matrix();

            rotationMatrix.RotateAt((float)angle, center);
            rotationMatrix.TransformPoints(points);
            rotationMatrix.Dispose();

            // Return the result
            return(RectangleFHelper.ComputeBoundingBox(points));
        }
Example #2
0
 public RectangleF TransformRectangle(RectangleF rectangle)
 {
     PointF[] points = RectangleFHelper.Corners(rectangle);
     TransformPoints(points);
     return(RectangleFHelper.ComputeBoundingBox(points));
 }