Home
-Calculate Sine-
Input:


Output:

<html>
<head>
<title>Sine</title>
</head>
<body bgcolor="#FFFFFF">
<SCRIPT type="text/javascript">
// written by: Crailin Mogged //
// This program shows the operations that make up the sine function.
function main()
{
   var inputAngle = parseFloat(sinInput.value);
   
   var lgSinOutput = 1, smSinOutput = 0, midSinOutput;
   var lgSlope = 0, smSlope = 1, midSlope;
   var lgAngle = 90, smAngle = 0, midAngle;
   
   var A,B,C,D,E,F,G,H,I;
   var J = 1, K = 1;
   
   var lgHeight, midHeight, smHeight;
   var lgHghtMinusK, smHghtPlusK;
   
   var i;
   
   var lessThanZero = 0;
   
   if (inputAngle % 360 > 180)
   lessThanZero = 1;
   if ((inputAngle % 360 > -180) && (inputAngle % 360 < 0))
   lessThanZero = 1;
   if (inputAngle < 0)
   inputAngle = -inputAngle;
   
   inputAngle = inputAngle % 180;
   if (inputAngle > 90)
   inputAngle = 90 - (inputAngle - 90);
   
   for (i = 0; i < 16; i++) // The number of loops is equal to 16
   {                        // The more loops, the more accurate
      // This is the formula found in "http://cchm86.com/deriving_pi/"
      A = J * 2;
      B = Math.sqrt(A);
      C = B - 1;
      D = 1 / K;
      K = C * D;
      
      E = 1 - K;
      F = E / 2;
      G = F + K;
      H = G * F;
      I = H * 2;
      J = 1 - I;
      
      lgHeight = lgSinOutput + (1 - lgSinOutput) / 2;
      lgHghtMinusK = lgHeight - K * lgSlope / 2;
      
      smHeight = smSinOutput + (1 - smSinOutput) / 2;
      smHghtPlusK = smHeight + K * smSlope / 2;
      
      midHeight = (lgHghtMinusK - smHghtPlusK) / 2 + smHghtPlusK;
      midSinOutput = midHeight - (1 - midHeight);
      
      
      lgHeight = lgSlope + (1 - lgSlope) / 2;
      lgHghtMinusK = lgHeight - K * smSinOutput / 2;
      
      smHeight = smSlope + (1 - smSlope) / 2;
      smHghtPlusK = smHeight + K * lgSinOutput / 2;
      
      midHeight = (lgHghtMinusK - smHghtPlusK) / 2 + smHghtPlusK;
      midSlope = midHeight - (1 - midHeight);
      
      midAngle = (lgAngle - smAngle) / 2 + smAngle;
      
      if (inputAngle >= midAngle)
      {
         smAngle = midAngle;
         smSinOutput = midSinOutput;
         smSlope = midSlope;
      }
      else
      {
         lgAngle = midAngle;
         lgSinOutput = midSinOutput;
         lgSlope = midSlope;
      }
   }
   
   if (lessThanZero)
   sinOutput.value = Math.round(-midSinOutput * 10000) / 10000;
   else
   sinOutput.value = Math.round(midSinOutput * 10000) / 10000;
}
</SCRIPT>

<H4>
<CENTER>
<INPUT type="button" value="Compute" onClick="main();">
</CENTER>
-Calculate Sine-
<HR>
Input:
<BR>
<INPUT id="sinInput" type="text" size="20" value="">
<BR>
<BR>
Output:
<BR>
<INPUT id="sinOutput" type="text" size="20" value="">
<HR>
</body>
</html>