C# 旋转多边形(三角形)
我有一个方法是绘制一个多边形,然后将该多边形向右旋转 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);
提前致谢。
I have a method which is to draw a polygon, and then rotate that polygon 90 degrees to the right so that its original top point is now pointing towards the right.
This is the code to draw the polygon(triangle) how ever I'm lost on how to rotate this.
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);
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://msdn.microsoft.com/en-us/library/s0s56wcf .aspx#Y609
您可以使用TransformPoints 方法仅旋转点
http://msdn.microsoft.com/en-us/library/s0s56wcf.aspx#Y609
You can use TransformPoints method of Matrix class to just rotate the points
请参阅这篇内容丰富的维基百科文章,了解旋转矩阵的详细解释。当旋转 90 度时,我们注意到 cos 90 会崩溃为零,产生以下简单变换,其中 x' 和 y' 是旋转后的坐标,< em>x 和 y 是之前的坐标。
在您的示例中应用这个简单的替换会产生以下代码。我还使用了速记集合初始值设定项表达式来增加可读性。
我还建议阅读线性代数,例如 Anton Rorres 等人< /em>。
See this informative Wikipedia article for a great explanation of rotation matrices. When rotating 90 degrees we note that cos 90 collapses into zero yielding the following simple transformation where x' and y' are your rotated coordinates and x and y are the previous coordinates.
Applying this simple replacement on your example yields the following code. I've also used a shorthand collection initializer expression for added readability.
I also recommend reading up on linear algebra using for example Anton Rorres, et al.
如果您旋转每个点,则可以旋转多边形。你还必须找出你的旋转中心O。可能你想使用你的多边形中心作为旋转中心。
You can rotate your polygon if you rotate every point. You also have to find out your rotation center O. Probably you want to use your polygon center as rotation center.