- Home /
Trying to obtain sine/cosine by angles giving me imprecise values
From the code:
double senoDoAngulo=Mathf.Asin((30 * Mathf.PI) / 180);
print ("Angle Sin: "+senoDoAngulo);
I obtain as answer: Cos Do Angle Sin: 0.551069617271423, not 0.5 as should it be, someone knows why and how to fix it? Thanks.
Don't you want $$anonymous$$athf.Sin()? Asin is for "arc-sine"
It's working well for Sine but not Cossine:
print ("Sin "+$$anonymous$$athf.Sin(89 * $$anonymous$$athf.PI / 180));
print ("Cossine"+$$anonymous$$athf.Cos(89 * $$anonymous$$athf.PI / 180));
print ("Sin "+$$anonymous$$athf.Sin(90 * $$anonymous$$athf.PI / 180));
print ("Cossine"+$$anonymous$$athf.Cos(90 * $$anonymous$$athf.PI / 180));
print ("Sin "+$$anonymous$$athf.Sin(91 * $$anonymous$$athf.PI / 180));
print ("Cossine"+$$anonymous$$athf.Cos(91 * $$anonymous$$athf.PI / 180));
Sin 0.9998477 Cossine 0.01745238 Sin 1 Cossine -4.371139E-08 Sin 0.9998477 Cossine -0.01745247
Answer by unimechanic · Nov 05, 2014 at 02:24 PM
Could be a problem due to float type precision. Try the .NET Math library:
http://msdn.microsoft.com/en-us/library/system.math.cos%28v=vs.110%29.aspx
Your answer
![](https://koobas.hobune.stream/wayback/20220613170729im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to check object "rotated" X degrees 1 Answer
Trying to get the angle of a camera object based on players forward, is not distance independent 0 Answers
Projectiles won't fire correctly. Help! (C#) 1 Answer
Problem with angles and rotations in a 2D top down space shooter 0 Answers
Create line that splits triangle 1 Answer