简体   繁体   中英

Rotating 2D object C #

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM