[英]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 度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.