• math.cos() incorrect
    4 replies, posted
So I just spent a couple hours trying to get something to work that requires cos to work properly, then I find out by simply comparing my calculator and a couple online calcs to a print of math.cos(), that math.cos() isn't even correct. Example: math.cos( 45 ) = 0.52532198881773 and a proper calculator = 0.707106781187. Fuck me. Am I doing something wrong here?
cos(45) = 0.70710678118 [B]degrees[/B], cos(45) = 0.52532198881 [B]radians[/B]. GMod's math fuction is giving you the calculation in radians. The conversion is pretty straightforward luckily: [IMG]http://cochranmath.pbworks.com/f/1495750232/conversions again!.gif[/IMG] [code]math.deg(math.cos(45))[/code] This will convert your radians calculation to degrees.
To add: You don't even need the formula for converting from degrees to radians, as Lua has a function to do that for you (but it's still useful to know). [lua]math.cos(math.rad(45))[/lua]
Thanks both of you.
[QUOTE=ZestyLemons;52633749]cos(45) = 0.70710678118 [B]degrees[/B], cos(45) = 0.52532198881 [B]radians[/B]. GMod's math fuction is giving you the calculation in radians. The conversion is pretty straightforward luckily: [IMG]http://cochranmath.pbworks.com/f/1495750232/conversions again!.gif[/IMG] [code]math.deg(math.cos(45))[/code] This will convert your radians calculation to degrees.[/QUOTE] Important correction... cos(45 [B]degrees[/B]) = 0.70710678118, cos(45 [B]radians[/B]) = 0.52532198881. and as Bo98 said: [lua]math.cos(math.rad(45))[/lua] Not the other way around.
Sorry, you need to Log In to post a reply to this thread.