Reputation: 13
I started a bit with C # using visual studio 2010
The program has three textBox and a button to rotate a 2D point I get these textBox coordenadaX, coordenadaY and angle need to calculate and display the new 2D point have the following code:
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);
}
}
eg User reports: coordenadaX = 10, coordenadaY = 10, Angle = 180 the correct answer would be the new 2D point: - 10: -10
Upvotes: 1
Views: 469
Reputation: 4867
Math.Sin
and Math.Cos
use radians, not degrees. Specify a rotation of pi
rather than 180 and you'll find that you get the correct answer.
Upvotes: 3