- Home /
Convert Mathf.Sin() radians to degrees
Hi.
I need to display some calculations on my screen, and I want to show some of them in degrees. The problem is taht unity calculates perfectly sin and cos in radians but I cant get it to convert them properly to degrees.
I've used the Rad2Deg variable, and even try it by the "manual way" like this:
cosOps=(360*Mathf.Sin(45))/2*Mathf.PI;
Thanks for the help!
Answer by whydoidoit · May 29, 2012 at 06:48 PM
It's looking for the parameter of Mathf.Sin to be in radians. The return value is going to be the resulting sin value. Mathf.Asin will return an angle in radians from a sin.
EDIT
Ok I'm going to try this again!
If you want to be able to input angles in degrees then you need to convert the angle you input into radians before getting the sine of the angle.
var myAngleInDegrees = 175;
var sinOfAngle = Mathf.Sin((myAngleInDegrees * Mathf.PI)/180);
if you have the sine of an angle and you want the angle in degrees
var mySineOfAngle = 0.4;
var angleOfSineInDegrees = (Mathf.ASin(mySineOfAngle) * 180) / Mathf.PI;
So Sin(45) looks like an angle in degrees. The Sin of an angle is going to be between -1 and 1 - so you can't convert that to anything using radians to degrees or whatever.
The ASin of a sine is going to return an angle in radians - you might want to convert that to degrees.
Hey - I just can't write the comment right - tried 3 times - must be tired :)
And for further clarification of my very murky comment $$anonymous$$ath.Sin expects to be given an angle in radians not in degrees. $$anonymous$$athf.Sin($$anonymous$$athf.PI)
Answer by threeup · May 29, 2012 at 10:27 PM
PI by 180 or 180 by PI is the ratio to use. General rule , if it is a big number ( 0 to 360) divide by 180, if it is small number (-1 to 1) multiply by 180.
angleDeg = 45f; angleRad = angleDeg * PI / 180;
sinAngleRad = Mathf.Sin(angleRad); sinAngleDeg = sinAngleRad*180/PI;
Your answer
Follow this Question
Related Questions
Mathf.Sin() & Mathf.Cos() 1 Answer
Clamp rotation of sprite? 0 Answers
How does this AND Mathf.Sin actually work?! 2 Answers
Snap the rotation 0 Answers