luxeon Posted July 13, 2009 Share Posted July 13, 2009 I wrote a code but it not working.. it show a strange value... but the corect value is 0.5 I know it can be written in another way: for example pi/6.. but is the particular case but how i can write for all the cases? the same problem is for cos, tan etc... <script type="text/javascript"> document.write(Math.sin(30)) </script> or <? $a=30; $b=sin($a); echo $b; ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 14, 2009 Share Posted July 14, 2009 The sine of 30 degrees is 0.5, but the JavaScript sine function [Math.sin()] uses Radians. To be honest, I don't recall what a Radian is exactly (been almost a decade since I took any advanced math classes), but using the calculator in Windows shows the sine of 30 radians to be -0.9880316240928618 (rounded), which is exactly what the javaScript code produces. Edit: The size of a radian is determined by the requirement that there are 2π radians in a circle. Thus 2π radians equals 360 degrees. This means that 1 radian = 180/π degrees, and 1 degree = π/180 radians. http://math.rice.edu/~pcmi/sphere/drg_txt.html So to get the sine of degrees use the following (replace 30 with the degrees you need to calculate): document.write(Math.sin(30*Math.PI/180)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.