Posted By

Scooter on 03/12/08


Tagged

math trigonometry


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

asifrizvigmailcom


Trigonometry Library


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com

Library of trigonometry functions, both circular and hyperbolic.

  1. <%
  2. ' ASP Trigonometry Library
  3. '
  4. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  5. '
  6. ' This work is licensed under the Creative Commons Attribution License. To view
  7. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  8. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  9. ' 94305, USA.
  10.  
  11. ' CIRCULAR FUNCTIONS
  12.  
  13. ' There are six basic trigonometric functions, three of which (sine, cosine, and tangent) are already defined in ASP.
  14. ' function sin() - Returns the sine of the specified angle.
  15. ' function cos() - Returns the cosine of the specified angle.
  16. ' function tan() - Returns the tangent of the specified angle.
  17.  
  18. ' The other three basic trigonometric functions are the multiplicative inverses of the previous three functions.
  19.  
  20. ' Returns the cosecant of the specified angle.
  21. function csc(x)
  22. csc = 1 / sin(x)
  23. end function
  24.  
  25. ' Returns the secant of the specified angle.
  26. function sec(x)
  27. sec = 1 / cos(x)
  28. end function
  29.  
  30. ' Returns the cotangent of the specified angle.
  31. function cot(x)
  32. cot = 1 / tan(x)
  33. end function
  34.  
  35. ' The following trigonometric functions are rarely used anymore, but are included in this function library for completeness.
  36.  
  37. ' Returns the versed sine (also called versine) of the specified angle.
  38. function versin(x)
  39. versin = 1 - cos(x)
  40. end function
  41.  
  42. ' Returns the coversed sine (also called coversine) of the specified angle.
  43. function coversin(x)
  44. coversin = 1 - sin(x)
  45. end function
  46.  
  47. ' Returns the haversed sine (also called haversine) of the specified angle.
  48. function haversin(x)
  49. haversin = versin(x) / 2
  50. end function
  51.  
  52. ' Returns the hacoversed sine (also called hacoversine, cohaversine, or havercosine) of the specified angle.
  53. function hacoversin(x)
  54. hacoversin = coversin(x) / 2
  55. end function
  56.  
  57. ' Returns the exsecant of the specified angle.
  58. function exsec(x)
  59. exsec = sec(x) - 1
  60. end function
  61.  
  62. ' Returns the excosecant of the specified angle.
  63. function excsc(x)
  64. excsc = csc(x) - 1
  65. end function
  66.  
  67. ' Each of the six basic trigonometric functions also has an inverse function.
  68.  
  69. ' Returns the angle whose sine is the specified number.
  70. function asin(x)
  71. asin = atn(x / sqr(-x * x + 1))
  72. end function
  73.  
  74. ' Returns the angle whose cosine is the specified number.
  75. function acos(x)
  76. acos = atn(-x / sqr(-x * x + 1)) + 2 * atn(1)
  77. end function
  78.  
  79. ' Returns the angle whose tangent is the specified number.
  80. ' This function is already defined in ASP, but has been aliased here for consistency with other programming languages.
  81. function atan(x)
  82. atan = atn(x)
  83. end function
  84.  
  85. ' Returns the angle whose cosecant is the specified number.
  86. function acsc(x)
  87. acsc = atn(x / sqr(x * x - 1)) + (sin(x) - 1) * (2 * atn(1))
  88. end function
  89.  
  90. ' Returns the angle whose secant is the specified number.
  91. function asec(x)
  92. asec = atn(x / sqr(x * x - 1)) + sin((x) - 1) * (2 * atn(1))
  93. end function
  94.  
  95. ' Returns the angle whose cotangent is the specified number.
  96. function acot(x)
  97. acot = atn(x) + 2 * atn(1)
  98. end function
  99.  
  100.  
  101. ' HYPERBOLIC FUNCTIONS
  102.  
  103. ' The hyperbolic functions are like the basic trigonometric functions, but for hyperbola instead of circles.
  104.  
  105. ' Returns the hyperbolic sine of the specified angle.
  106. function sinh(x)
  107. sinh = (exp(x) - exp(-x)) / 2
  108. end function
  109.  
  110. ' Returns the hyperbolic cosine of the specified angle.
  111. function cosh(x)
  112. cosh = (exp(x) + exp(-x)) / 2
  113. end function
  114.  
  115. ' Returns the hyperbolic tangent of the specified angle.
  116. function tanh(x)
  117. tanh = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
  118. end function
  119.  
  120. ' Returns the hyperbolic cosecant of the specified angle.
  121. function csch(x)
  122. csch = 2 / (exp(x) - exp(-x))
  123. end function
  124.  
  125. ' Returns the hyperbolic secant of the specified angle.
  126. function sech(x)
  127. sech = (2 / (exp(x) + exp(-x)))
  128. end function
  129.  
  130. ' Returns the hyperbolic cotangent of the specified angle.
  131. function coth(x)
  132. coth = (exp(x) + exp(-x)) / (exp(x) - exp(-x))
  133. end function
  134.  
  135. ' Just like in trigonometry, the six basic hyperbolic functions have inverse functions.
  136.  
  137. ' Returns the angle whose hyperbolic sine is the specified number.
  138. function asinh(x)
  139. asinh = log(x + sqr(x * x + 1))
  140. end function
  141.  
  142. ' Returns the angle whose hyperbolic cosine is the specified number.
  143. function acosh(x)
  144. acosh = log(x + sqr(x * x - 1))
  145. end function
  146.  
  147. ' Returns the angle whose hyperbolic tangent is the specified number.
  148. function atanh(x)
  149. atanh = log((1 + x) / (1 - x)) / 2
  150. end function
  151.  
  152. ' Returns the angle whose hyperbolic cosecant is the specified number.
  153. function acsch(x)
  154. acsch = log((sin(x) * sqr(x * x + 1) + 1) / x)
  155. end function
  156.  
  157. ' Returns the angle whose hyperbolic secant is the specified number.
  158. function asech(x)
  159. asech = log((sqr(-x * x + 1) + 1) / x)
  160. end function
  161.  
  162. ' Returns the angle whose hyperbolic cotangent is the specified number.
  163. function acoth(x)
  164. acoth = log((x + 1) / (x - 1)) / 2
  165. end function
  166.  
  167.  
  168. ' GUDERMANNIAN FUNCTIONS
  169.  
  170. ' The Gudermannian function relates the circular and hyperbolic trigonometric functions without resorting to complex numbers.
  171. function gd(x)
  172. gd = 2 * atn(tanh(x / 2))
  173. end function
  174.  
  175. ' Like other trigonometric and hyperbolic functions, Gudermannian has an inverse.
  176. function agd(x)
  177. agd = atanh(sin(x))
  178. end function
  179. %>

Report this snippet  

You need to login to post a comment.