Trigonometry help?

So I’m trying to figure out how to do some basic trig in Unity. I know I’m a little rusty, but this is terribly confusing.

My calculator says Cos(60)*10 = 5, but when I do Mathf.Cos(60)*10, I get -9.52413.

Could somebody un-stupid me?

1 Answer

1

Mathf.Cos expect the angle in radians, not degrees. To make our lives easier, Unity provides the constants Mathf.Deg2Rad and Mathf.Rad2Deg: just multiply the value by the appropriate constant to convert degrees to/from radians. In the example:

print("Cos(60) = "+Mathf.Cos(60 * Mathf.Deg2Rad));

what will print 0.5

I just like to note that most programming languages use radians in all trigonometric functions. Radians makes from a mathematical point of view much more sense than 0° - 360° which is just a magic number ;) See <a hreF="http://en.wikipedia.org/wiki/Radian">Radian(wikipedia)</a>

–

Exactly - 360 is used due to some obscure ancient reason, but means nothing from a math point of view. This magic number almost became 400 when the metric system was being defined - someone got smart and proposed the grado, a "metric flavored" unit to replace the old and dusty degree (400 gradi == 360 degrees)

–

If you ever find a trigo function taking degrees, it's because the conversion is performed inside before calculating the cos. Otherwise, it just wouldn't make sense.

–