Published in: ASP
URL: http://reusablecode.blogspot.com
Library of trigonometry functions, both circular and hyperbolic.
<% ' ASP Trigonometry Library ' ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. ' ' This work is licensed under the Creative Commons Attribution License. To view ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California ' 94305, USA. ' CIRCULAR FUNCTIONS ' There are six basic trigonometric functions, three of which (sine, cosine, and tangent) are already defined in ASP. ' function sin() - Returns the sine of the specified angle. ' function cos() - Returns the cosine of the specified angle. ' function tan() - Returns the tangent of the specified angle. ' The other three basic trigonometric functions are the multiplicative inverses of the previous three functions. ' Returns the cosecant of the specified angle. function csc(x) csc = 1 / sin(x) end function ' Returns the secant of the specified angle. function sec(x) sec = 1 / cos(x) end function ' Returns the cotangent of the specified angle. function cot(x) cot = 1 / tan(x) end function ' The following trigonometric functions are rarely used anymore, but are included in this function library for completeness. ' Returns the versed sine (also called versine) of the specified angle. function versin(x) versin = 1 - cos(x) end function ' Returns the coversed sine (also called coversine) of the specified angle. function coversin(x) coversin = 1 - sin(x) end function ' Returns the haversed sine (also called haversine) of the specified angle. function haversin(x) haversin = versin(x) / 2 end function ' Returns the hacoversed sine (also called hacoversine, cohaversine, or havercosine) of the specified angle. function hacoversin(x) hacoversin = coversin(x) / 2 end function ' Returns the exsecant of the specified angle. function exsec(x) exsec = sec(x) - 1 end function ' Returns the excosecant of the specified angle. function excsc(x) excsc = csc(x) - 1 end function ' Each of the six basic trigonometric functions also has an inverse function. ' Returns the angle whose sine is the specified number. function asin(x) asin = atn(x / sqr(-x * x + 1)) end function ' Returns the angle whose cosine is the specified number. function acos(x) acos = atn(-x / sqr(-x * x + 1)) + 2 * atn(1) end function ' Returns the angle whose tangent is the specified number. ' This function is already defined in ASP, but has been aliased here for consistency with other programming languages. function atan(x) atan = atn(x) end function ' Returns the angle whose cosecant is the specified number. function acsc(x) acsc = atn(x / sqr(x * x - 1)) + (sin(x) - 1) * (2 * atn(1)) end function ' Returns the angle whose secant is the specified number. function asec(x) asec = atn(x / sqr(x * x - 1)) + sin((x) - 1) * (2 * atn(1)) end function ' Returns the angle whose cotangent is the specified number. function acot(x) acot = atn(x) + 2 * atn(1) end function ' HYPERBOLIC FUNCTIONS ' The hyperbolic functions are like the basic trigonometric functions, but for hyperbola instead of circles. ' Returns the hyperbolic sine of the specified angle. function sinh(x) sinh = (exp(x) - exp(-x)) / 2 end function ' Returns the hyperbolic cosine of the specified angle. function cosh(x) cosh = (exp(x) + exp(-x)) / 2 end function ' Returns the hyperbolic tangent of the specified angle. function tanh(x) tanh = (exp(x) - exp(-x)) / (exp(x) + exp(-x)) end function ' Returns the hyperbolic cosecant of the specified angle. function csch(x) csch = 2 / (exp(x) - exp(-x)) end function ' Returns the hyperbolic secant of the specified angle. function sech(x) sech = (2 / (exp(x) + exp(-x))) end function ' Returns the hyperbolic cotangent of the specified angle. function coth(x) coth = (exp(x) + exp(-x)) / (exp(x) - exp(-x)) end function ' Just like in trigonometry, the six basic hyperbolic functions have inverse functions. ' Returns the angle whose hyperbolic sine is the specified number. function asinh(x) asinh = log(x + sqr(x * x + 1)) end function ' Returns the angle whose hyperbolic cosine is the specified number. function acosh(x) acosh = log(x + sqr(x * x - 1)) end function ' Returns the angle whose hyperbolic tangent is the specified number. function atanh(x) atanh = log((1 + x) / (1 - x)) / 2 end function ' Returns the angle whose hyperbolic cosecant is the specified number. function acsch(x) acsch = log((sin(x) * sqr(x * x + 1) + 1) / x) end function ' Returns the angle whose hyperbolic secant is the specified number. function asech(x) asech = log((sqr(-x * x + 1) + 1) / x) end function ' Returns the angle whose hyperbolic cotangent is the specified number. function acoth(x) acoth = log((x + 1) / (x - 1)) / 2 end function ' GUDERMANNIAN FUNCTIONS ' The Gudermannian function relates the circular and hyperbolic trigonometric functions without resorting to complex numbers. function gd(x) gd = 2 * atn(tanh(x / 2)) end function ' Like other trigonometric and hyperbolic functions, Gudermannian has an inverse. function agd(x) agd = atanh(sin(x)) end function %>
You need to login to post a comment.
