July 25, 2000  Animation with Math.sin()
July 25, 2000 Animation with Math.sin() Tips: July 2000
Yehuda Shiran, Ph.D.

cos()
, acos()
, sin()
, asin()
, tang()
, atan()
, and atan2()
. All angles in JavaScript are measured in radians. You should know how to convert an angle from degrees to radians and vice versa. Check your conversion with the following table:
Degrees  Radians 
0  0 
90  0.5*PI 
180  PI 
270  1.5*PI 
360  2*PI 
sin()
TheMath.sin()
method accepts one argument (an angle in radians) and returns its sine value. The following statement prints "1":
document.write(Math.sin(0.5 * Math.PI));
The Math.sin()
method is useful in animation applications. If an object A revolves around object B in a constant radius orbit, its x location can be derived by multiplying the orbiting raidus by the sine of the angle that the radius makes with the upright ray.
asin()
TheMath.asin()
method accepts one argument and returns the arc sine (the angle that the given number is its sine value) of the argument, in radians. The following statement prints the value of PI:
document.write(2 * Math.asin(1));