xmd79

MathTrigonometry

Oct 7th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.62 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © RicardoSantos
  3.  
  4. //@version=5
  5.  
  6. // @description Trigonometric methods.
  7. library("MathTrigonometry")
  8. // reference:
  9. // https://www.brighthubeducation.com/homework-math-help/72270-trigonometry-functions-a-trig-functions-list/
  10. // https://github.com/mathnet/mathnet-numerics/blob/a50d68d52def605a53d129cc60ea3371a2e97548/src/Numerics/Trigonometry.cs
  11.  
  12. // @function Normalized sinc function.
  13. // @param value float, value.
  14. // @returns float.
  15. export sinc (float value) => //{
  16. float _z = math.pi * value
  17. if math.abs(_z) <= 1.0e-15 // almost equal
  18. 1.0
  19. else
  20. math.sin(_z) / _z
  21. //}
  22.  
  23. //######################################
  24.  
  25. // @function Cotangent of value.
  26. // @param value float, value.
  27. // @returns float.
  28. export cot (float value) => //{
  29. 1.0 / math.tan(value)
  30. //}
  31.  
  32. // @function Cosecant of value.
  33. // @param value float, value.
  34. // @returns float.
  35. export csc (float value) => //{
  36. 1.0 / math.sin(value)
  37. //}
  38.  
  39. // @function Secant of value.
  40. // @param value float, value.
  41. // @returns float.
  42. export sec (float value) => //{
  43. 1.0 / math.cos(value)
  44. //}
  45.  
  46. ///#################
  47.  
  48. // @function Arc cotangent of value.
  49. // @param value float, adjacent value.
  50. // @returns float.
  51. export acot (float value) => //{
  52. math.atan(1.0 / value)
  53. //}
  54.  
  55. // @function Arc secant of value.
  56. // @param value float, hypotenuse value.
  57. // @returns float.
  58. export asec (float value) => //{
  59. math.acos(1.0 / value)
  60. //}
  61.  
  62. // @function Arc cosecant of value.
  63. // @param value float, hipotenuse value.
  64. // @returns float.
  65. export acsc (float value) => //{
  66. math.atan(1.0 / value)
  67. //}
  68.  
  69. //################
  70.  
  71. // @function Hyperbolic sine of angle.
  72. // @param angle float, value.
  73. // @returns float.
  74. export sinh (float angle) => //{
  75. (math.exp(angle) - math.exp(-angle)) / 2.0
  76. //}
  77.  
  78. // @function Hyperbolic cosine of angle.
  79. // @param angle float, value.
  80. // @returns float.
  81. export cosh (float angle) => //{
  82. (math.exp(angle) + math.exp(-angle)) / 2.0
  83. //}
  84.  
  85. // @function Hyperbolic tangent of angle.
  86. // @param angle float, value.
  87. // @returns float.
  88. export tanh (float angle) => //{
  89. if angle > 19.1
  90. 1.0
  91. else if angle -19.1
  92. -1.0
  93. else
  94. float _e1 = math.exp(angle)
  95. float _e2 = math.exp(-angle)
  96. (_e1 - _e2) / (_e1 + _e2)
  97. //}
  98.  
  99. // @function Hyperbolic cotangent of angle.
  100. // @param angle float, value.
  101. // @returns float.
  102. export coth (float angle) => //{
  103. if angle > 19.1
  104. 1.0
  105. else if angle -19.1
  106. -1.0
  107. else
  108. float _e1 = math.exp(angle)
  109. float _e2 = math.exp(-angle)
  110. (_e1 + _e2) / (_e1 - _e2)
  111. //}
  112.  
  113. // @function Hyperbolic secant of angle.
  114. // @param angle float, value.
  115. // @returns float.
  116. export sech (float angle) => //{
  117. 1.0 / cosh(angle)
  118. //}
  119.  
  120. // @function Hyperbolic cosecant of angle.
  121. // @param angle float, value.
  122. // @returns float.
  123. export csch (float angle) => //{
  124. 1.0 / sinh(angle)
  125. //}
  126.  
  127. //#############################
  128.  
  129. // @function Hyperbolic area sine.
  130. // @param value float, value.
  131. // @returns float.
  132. export asinh (float value) => //{
  133. //https://github.com/mathnet/mathnet-numerics/blob/a50d68d52def605a53d129cc60ea3371a2e97548/src/Numerics/Trigonometry.cs#L711
  134. float _absv = math.abs(value)
  135. if _absv >= 268435456.0
  136. math.sign(value) * (math.log(_absv) + math.log(2.0))
  137. else
  138. math.sign(value) * math.log(_absv + math.sqrt(1.0 + math.pow(value, 2.0)))
  139. //}
  140.  
  141. // @function Hyperbolic area cosine.
  142. // @param value float, value.
  143. // @returns float.
  144. export acosh (float value) => //{
  145. //https://github.com/mathnet/mathnet-numerics/blob/a50d68d52def605a53d129cc60ea3371a2e97548/src/Numerics/Trigonometry.cs#L737
  146. float _absv = math.abs(value)
  147. if _absv >= 268435456.0
  148. math.log(value) + math.log(2.0)
  149. else
  150. math.log(value + (math.sqrt(value -1.0) * math.sqrt(value + 1.0)))
  151. //}
  152.  
  153. // @function Hyperbolic area tangent.
  154. // @param value float, value.
  155. // @returns float.
  156. export atanh (float value) => //{
  157. 0.5 * math.log((value + 1.0) / (value - 1.0))
  158. //}
  159.  
  160. // @function Hyperbolic area cotangent.
  161. // @param value float, value.
  162. // @returns float.
  163. export acoth (float value) => //{
  164. 0.5 * math.log((value + 1.0) / (value - 1.0))
  165. //}
  166.  
  167. // @function Hyperbolic area secant.
  168. // @param value float, value.
  169. // @returns float.
  170. export asech (float value) => //{
  171. acosh(1.0 / value)
  172. //}
  173.  
  174. // @function Hyperbolic area cosecant.
  175. // @param value float, value.
  176. // @returns float.
  177. export acsch (float value) => //{
  178. asinh(1.0 / value)
  179. //}
  180.  
  181.  
Advertisement
Add Comment
Please, Sign In to add comment