How to rotate 2d vector?

Martin Meeser picture Martin Meeser · Apr 2, 2014 · Viewed 49k times · Source

I have this:

static double[] RotateVector2d(double x, double y, double degrees)
{
    double[] result = new double[2];
    result[0] = x * Math.Cos(degrees) - y * Math.Sin(degrees);
    result[1] = x * Math.Sin(degrees) + y * Math.Cos(degrees);
    return result;
}

When I call

RotateVector2d(1.0, 0, 180.0)

the result is: [-0.59846006905785809, -0.80115263573383044]

What to do so that the result is [-1, 0] ?

What am I doing wrong?

Answer

reggaeguitar picture reggaeguitar · Apr 2, 2014

The angle is measured in radians, not degrees. See http://msdn.microsoft.com/en-us/library/system.math.cos(v=vs.110).aspx