- Home /
how to properly use mathf cosinus?
what ever I do I get totally wrong resault
http://www.mathsisfun.com/geometry/unit-circle.html
http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Cos.html
cos 0.5f should be 60°
cos 0 should be 90°
but they aren't:
Debug.Log(Mathf.Cos(0.5f) ); // 50.28178
Debug.Log(Mathf.Cos(0f) ); // 1
Debug.Log(Mathf.Cos(0.5f) * Mathf.Deg2Rad); // 0.01745329
Debug.Log(Mathf.Cos(0.5f) * Mathf.Rad2Deg); // 57.29578
so what am I doing wrong?
Answer by DaveA · Oct 10, 2013 at 05:34 PM
The result of cos is always from -1 to 1. I think you want Mathf.Acos
ok thanks this works now
Debug.Log($$anonymous$$athf.Acos(0f) * $$anonymous$$athf.Rad2Deg);
DANG I thought I'll get neg result with this, ...
guesss I'll have to find some other solution to this, ...
got it:
http://answers.unity3d.com/questions/162177/vector2angles-direction.html
$$anonymous$$aybe tell us what it is you are trying to do? :D
Answer by meat5000 · Oct 10, 2013 at 05:31 PM
Cos (60) = 0.5
Cos^-1 (0.5) = 60
This is in degrees/
Math.f functions work in Radians
Take Degrees x Pi/180 to find radians.