Monday, February 18, 2008

Trigonometry, Part 3

I was hoping to publish every Saturday, but this past Saturday I got sidetracked. So without further ado, I bring you the next installment in the trigonometry series of articles.


Each of the six basic trigonometric functions has an inverse function. The inverse functions for sine, cosine, and tangent (arcsine, arcosine, and arctangent, respectively) are already defined natively in PHP. In ASP, only the inverse function for tangent (arctangent) is defined, but we will create an adapter for it to be consistent with the abbreviation in PHP. We also need to define some constants that are already present in PHP but not in ASP.


ASP

  1. Const M_PI = 3.14159265358979323846
  2. Const M_PI_2 = M_PI / 2
  3. function asin(x)
  4.     asin = atn(x / sqr(1 - x ^ 2))
  5. end function
  6. function acos(x)
  7.     acos = M_PI_2 - asin(x)
  8. end function
  9. function atan(x)
  10.     atan = atn(x)
  11. end function

As you can probably guess, the inverse functions for cosecant, secant, and cotangent are arccosecant, arcsecant, and arccotangent.


ASP

  1. function acsc(x)
  2.     acsc = asin(1 / x)
  3. end function
  4. function asec(x)
  5.     asec = M_PI_2 - acsc(x)
  6. end function
  7. function acot(x)
  8.     acot = M_PI_2 - atn(x)
  9. end function

PHP

  1. function acsc($x)
  2. {
  3.     return asin(1 / $x);
  4. }
  5. function asec($x)
  6. {
  7.     return (M_PI_2 - acsc($x));
  8. }
  9. function acot($x)
  10. {
  11.     return (M_PI_2 - atan($x));
  12. }

Next time we'll do something different for a change. I promise.

No comments: