- Home /
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?
Answer by aldonaletto · May 18, 2012 at 11:26 PM
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 program$$anonymous$$g 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 ;)
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.
Your answer
Follow this Question
Related Questions
simulate a circle move 2 Answers
Move and Rotate player in circular motion? 2 Answers
sin error invee sin error 1 Answer
Move In Circle relative to rotation. 1 Answer
Cos creates problems with addforce 0 Answers