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
https://forums.phpfreaks.com/topic/165784-functions-sin-cos-etc/
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));

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.