使用 C# windows 应用程序在不改变位置的情况下旋转三角形的度数?

编程入门 行业动态 更新时间:2024-10-28 17:18:45
本文介绍了使用 C# windows 应用程序在不改变位置的情况下旋转三角形的度数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..
private void panel1_Paint(object sender, PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
    Point[] array = { new Point(639, 75), new Point(606, 124), new oint(664, 123) };
    matrix.TransformPoints(array);
    e.Graphics.Transform = matrix;

    e.Graphics.RotateTransform(ang, MatrixOrder.Append);

    myPen2.RotateTransform(ang, MatrixOrder.Append);

    e.Graphics.DrawPolygon(myPen2, array);
}

我使用的是 Visual Studio 2010.上面的代码应该用于在 C# 中绘制一个三角形,但是如果没有绘制三角形位置,我无法旋转它.我怎样才能做到这一点?

I'm using Visual Studio 2010. The above code should be for drawing a triangle in C#, but I can't rotate it without drawn triangle location. How can I achieve that?

推荐答案

这将进行轮换:

private void panel1_Paint(object sender, PaintEventArgs e)
{
    Pen myPen = new Pen(Color.Blue, 1);
    Pen myPen2 = new Pen(Color.Red, 1);
    Point[] array = { new Point(239, 75), new Point(206, 124), new Point(264, 123) };

    float x = array.Select(_ => _.X).Sum() / array.Length;
    float y = array.Select(_ => _.Y).Sum() / array.Length;

    e.Graphics.DrawPolygon(myPen, array);

    e.Graphics.TranslateTransform(x,y);
    e.Graphics.RotateTransform(ang);
    e.Graphics.TranslateTransform(-x, -y);

    e.Graphics.DrawPolygon(myPen2, array);
}

无需旋转简单的 Pen,但对于更高级的笔来说,这很可能是需要的..

No need to rotate a simple Pen although for more adavanced pens this may well be called for..

我已经计算了旋转中心坐标,然后将 Graphics' 原点移动到那里,旋转它然后移回.然后我们就可以画了.

I have calculated the rotation center coordinates and then move the Graphics' origin there, rotate it and then move back. Then we can draw.

要测试您可以使用轨迹栏:

To test you can use a trackbar:

float ang = 0f;

private void trackBar1_Scroll(object sender, EventArgs e)
{
    ang = (float) trackBar1.Value;
    panel1.Invalidate();
}

这篇关于使用 C# windows 应用程序在不改变位置的情况下旋转三角形的度数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 12:36:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:角形   度数   应用程序   情况下   位置

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!