C# 从原点出发画射线我想用代码实现从坐标原点(0,0),绘制一定角度的射线,如何去做?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/17 00:54:38
C# 从原点出发画射线我想用代码实现从坐标原点(0,0),绘制一定角度的射线,如何去做?
C# 从原点出发画射线
我想用代码实现从坐标原点(0,0),绘制一定角度的射线,如何去做?
C# 从原点出发画射线我想用代码实现从坐标原点(0,0),绘制一定角度的射线,如何去做?
public partial class Form1 : Form
{
private const int cnt = 15;//数量
private float angle = (float)(2 * Math.PI / cnt);
private const int R = 100;//长度
public Form1()
{
InitializeComponent();
this.Paint += this.Form1_Paint;
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
for (int n = 0; n < cnt; n++)
{
float a = n * angle;
Point ps = new Point(0, 0);
Point pe = new Point((int)(R * Math.Cos(a)), (int)(R * Math.Sin(a)));
Change(ref ps);
Change(ref pe);
e.Graphics.DrawLine(new Pen(Color.Red), ps, pe);
}
}
//转换坐标系
private void Change(ref Point p)
{
Size sz = this.ClientSize;
p.X += sz.Width / 2;
p.Y = sz.Height / 2 - p.Y;
}
}