1

我使用 Visual Studio 2010 开始使用 C#

该程序有三个文本框和一个按钮来旋转一个二维点我得到这些文本框 coordenadaX、coordenadaY 和角度需要计算和显示新的二维点有以下代码:

  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, Angle = 180 正确答案是新的 2D 点:- 10: -10

4

1 回答 1

3

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.

于 2012-07-24T20:24:12.930 回答