这个C#里画五角星的函数,高手解释一下,谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/29 00:03:57
protected override void OnPaint(PaintEventArgs args)
{
Graphics grfx = args.Grphics;

int cx = 300;
int cy = 160;

Point[] apt = new Point[5];
for (int i = 0; i< apt.Length; i++)
{
double dAngle = (i * 0.8 - 0.5) * Math.PI;
apt[i] = new Point((int)(cx * (0.25 + 0.24 * Math.Cos(dAgngle))),(int)(cy * (0.5 + 0.48 * Math.Sin(dAngle))));
}

grfx.FillPolygon(new SolidBrush(Color.Red),
apt,
FillMode.Winding);
}

apt[i] = new Point((int)(cx * (0.25 + 0.24 * Math.Cos(dAgngle))),(int)(cy * (0.5 + 0.48 * Math.Sin(dAngle))))
这一步看不懂
不是坐标点看不懂,是这个算法不懂,0.25,0.24这些算法是怎么得到?

apt[i] = new Point((int)(cx * (0.25 + 0.24 * Math.Cos(dAgngle))),(int)(cy * (0.5 + 0.48 * Math.Sin(dAngle))))

分解开来,是:
new Point(x,y);
x = (int)(cx * (0.25 + 0.24 * Math.Cos(dAgngle)))
0.24乘以dAgngle的COS值,加上0.25,再把结果乘以cx,最后把运算结果转换成int类型
y = (int)(cy * (0.5 + 0.48 * Math.Sin(dAngle)))
0.48乘以dAgngle的SIN值,加上0.5,再把结果乘以cy,最后把运算结果转换成int类型