C#中,两点确定一直线,想要让这条直线绕某个定点旋转?
发布网友
发布时间:2024-10-24 16:51
我来回答
共1个回答
热心网友
时间:2024-10-30 05:18
这要用到数学中的正弦,余弦。
先定义这些变量
private Pen pen = new Pen(Color.Red);
private float x1 = 200;
private float y1 = 200;
private float x2 = 250;
private float y2 = 200;
private double r = 50;
private double angle = 0;
private double degress = 0;
往窗体里拖进一个timer控件,设置它的间隔,在它的tick事件里写如下代码
private void timer1_Tick(object sender, EventArgs e)
{
using(Graphics g = pictureBox1.CreateGraphics())
{
g.Clear(Color.White);
g.DrawLine(pen,x1,y1,x2,y2);
degress+=10;
angle = Math.PI * degress / 180.0;
x2 = (float)(250 - r + Math.Cos(angle) * r);
y2 = (float)(200 - Math.Sin(angle) * r);
}
}
然后还要启动timer.start();