C# 旋转多边形(三角形)

C# 旋转多边形(三角形),c#,rotation,geometry,C#,Rotation,Geometry,我有一个方法,就是画一个多边形,然后将多边形向右旋转90度,使其原始顶点现在指向右侧 这是绘制多边形(三角形)的代码,我对如何旋转这个很迷茫 Point[] points = new Point[3]; points[0] = new Point((int)top, (int)top); points[1] = new Point((int)top - WIDTH / 2, (int)top + HEIGHT); points[2] = new Point((int)top + WIDTH /

我有一个方法,就是画一个多边形,然后将多边形向右旋转90度,使其原始顶点现在指向右侧

这是绘制多边形(三角形)的代码,我对如何旋转这个很迷茫

Point[] points = new Point[3];
points[0] = new Point((int)top, (int)top);
points[1] = new Point((int)top - WIDTH / 2, (int)top + HEIGHT);
points[2] = new Point((int)top + WIDTH / 2, (int)top + HEIGHT);
paper.FillPolygon(normalBrush, points);

提前感谢。

如果需要,可以旋转多边形。你还必须找出你的旋转中心O。也许你想用你的多边形中心作为旋转中心。

您可以使用矩阵类的方法仅旋转点

有关旋转矩阵的详细说明,请参见。当旋转90度时,我们注意到cos 90收缩为零,产生以下简单变换,其中x'和y'是旋转坐标,x和y是先前的坐标

x' = -y
y' = x
在您的示例中应用这个简单的替换将产生以下代码。为了增加可读性,我还使用了一个速记集合初始值设定项表达式

var points = new[]
{
    new Point(-(int) top, (int) top),
    new Point((int) -(top + HEIGHT), (int) top - WIDTH/2),
    new Point((int) -(top + HEIGHT), (int) top + WIDTH/2)
};

paper.FillPolygon(normalBrush, points);

我还建议大家阅读线性代数,例如。

你想旋转多边形本身还是只旋转它?你应该使用三角学,基本上是在正确的时间应用一些sin,cos+1@TransformPoints链接。但是你发布的当前代码可能没有那么有用,是吗?@duedl0r如果最终他想旋转它,那么他不需要旋转点;只需创建矩阵并将其指定给图形对象。所以我认为它是有用的。是的,你说得对。但前提是这是唯一的目标,对吗?旋转中心可能也有问题。因此,您必须将其移动到(x/y),旋转,然后再将其移回..他可以在绘制对象后重置变换,也可以使用矩阵指定旋转中心b.RotateAt方法而不是旋转方法
var points = new[]
{
    new Point(-(int) top, (int) top),
    new Point((int) -(top + HEIGHT), (int) top - WIDTH/2),
    new Point((int) -(top + HEIGHT), (int) top + WIDTH/2)
};

paper.FillPolygon(normalBrush, points);