1
我使用Visual Studio 2010開始有點用C#旋轉2D對象C#
方案有3個文本框和一個按鈕,旋轉2D點我得到這些的textBox coordenadaX,coordenadaY和角度需要計算和顯示新的2D點有以下代碼:
private void button1_Click(object sender, EventArgs e)
{
float x = float.Parse(textX.Text);
float Y = float.Parse(textY.Text);
double angulo = float.Parse(textAng.Text);
rotate(x, Y, angulo);
}
private void rotate(float cordX, float cordY, double angle)
{
double s = Math.Sin(angle);
double c = Math.Cos(angle);
double newX = cordX * c - cordY * s;
double newY = cordX * s + cordY * c;
lblResult.Text = ("" + newX + " : " + "" + newY);
}
}
例如用戶報告:coordenadaX = 10,coordenadaY = 10,角= 180的正確答案將是新的2D點: - 10:-10