如何在 C# 中旋转正多边形

How do I rotate a Regular polygon in C#

我需要将正多边形围绕设定的中心旋转给定度数,有人可以帮忙吗? 我使用这段代码生成正多边形

private static void DrawRegularPolygon(PointF center, // center Coordinates of circle
     int vertexes, // Number of vertices
     float radius, // Radius
     Graphics graphics)
    {
        Pen pen;
        var angle = Math.PI * 2 / vertexes;
        var Rotationangle = (45/180) * Math.PI;

        var points = Enumerable.Range(0, vertexes)
        .Select(i => PointF.Add(center, new SizeF((float)Math.Sin(i * angle) * radius, (float)Math.Cos(i * angle) * radius )));

        if (vertexes%2 == 0)
        {
            pen = new Pen(Color.Red);
        }
        else
        {
            pen = new Pen(Color.Black);
        }

        graphics.DrawPolygon(pen, points.ToArray());
        //graphics.DrawEllipse(Pens.Aqua, new RectangleF(PointF.Subtract(center, new SizeF(radius, radius)), new SizeF(radius * 2, radius * 2)));
    }

尝试这些行:

graphics.TranslateTransform(center.X, center.Y);
graphics.RotateTransform(180f);
graphics.TranslateTransform(-center.X, -center.Y);
graphics.DrawPolygon(pen, points.ToArray());

我可以在绘制之前将多边形旋转 180 度。