Home > Blockchain >  Why is the Cos function in C# giving me wrong answers?
Why is the Cos function in C# giving me wrong answers?

Time:09-15

I have a method, in which I am using the Cos() Function from the namespace "Mathf". Sadly, when I give, for example the in put of 45 it returns 0,52532, which is wrong. Using a calculator I get the correct answer of 6.283185 Radians.

float angle = 45;
Debug.Log(Mathf.Cos(angle));

Prints out:

0,525322

Can anyone help me out here? I am very confused right now

CodePudding user response:

You need to convert to radians.

float angle = 45;
Debug.Log(Mathf.Cos(angle * Math.PI / 180.0f));
  • Related