Saturday, February 9, 2008

Trigonometry, Part 2

As promised, this week we're building some special trigonometry functions using the functions we wrote last week: versed sine (or versine), coversed sine (or coversine), haversed sine (or haversine), hacoversed sine (or hacoversine), exsecant, and excosecant. Actually, to be honest, only two of those build on the functions from last week.


ASP

  1. function versin(x)
  2.     versin = 1 - cos(x)
  3. end function
  4. function coversin(x)
  5.     coversin = 1 - sin(x)
  6. end function
  7. function haversin(x)
  8.     haversin = versin(x) / 2
  9. end function
  10. function hacoversin(x)
  11.     hacoversin = coversin(x) / 2
  12. end function
  13. function exsec(x)
  14.     exsec = sec(x) - 1
  15. end function
  16. function excsc(x)
  17.     excsc = csc(x) - 1
  18. end function

PHP

  1. function versin($x)
  2. {
  3.     return (1 - cos($x));
  4. }
  5. function coversin($x)
  6. {
  7.     return (1 - sin($x));
  8. }
  9. function haversin($x)
  10. {
  11.     return (versin($x) / 2);
  12. }
  13. function hacoversin($x)
  14. {
  15.     return (coversin($x) / 2);
  16. }
  17. function exsec($x)
  18. {
  19.     return (sec($x) - 1);
  20. }
  21. function excsc($x)
  22. {
  23.     return (csc($x) - 1);
  24. }

Next week, the fun continues with inverse trigonometric functions.

No comments: