Saturday, February 2, 2008

Trigonometry, Part 1

Both ASP and PHP contain three basic trigonometry functions: sin(), cos(), and tan(). You may remember from school that there are three more basic trigonometry functions: cosecant, secant, and cotangent. It might be handy to have some functions for these too.


ASP

  1. function csc(x)
  2.     csc = 1 / sin(x)
  3. end function
  4. function sec(x)
  5.     sec = 1 / cos(x)
  6. end function
  7. function cot(x)
  8.     cot = 1 / tan(x)
  9. end function

PHP

  1. function csc($x)
  2. {
  3.     return (1 / sin($x));
  4. }
  5. function sec($x)
  6. {
  7.     return (1 / cos($x));
  8. }
  9. function cot($x)
  10. {
  11.     return (1 / tan($x));
  12. }

Next week we'll build off some of these basic functions to make some special functions.

No comments: