Jump to content

Functions sin, cos... etc


luxeon

Recommended Posts

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;
?>

 

Link to comment
Share on other sites

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));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.