Math.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. <h1>[name]</h1>
  12. <div class="desc">Math utility functions</div>
  13. <h2>Properties</h2>
  14. <h2>Methods</h2>
  15. <h3>[method:Float clamp]( [page:Float value], [page:Float min], [page:Float max] )</h3>
  16. <div>
  17. value — Value to be clamped.<br />
  18. min — Minimum value<br />
  19. max — Maximum value.
  20. </div>
  21. <div>
  22. Clamps the *value* to be between *min* and *max*.
  23. </div>
  24. <h3>[method:Float degToRad]( [page:Float degrees] )</h3>
  25. <div>
  26. degrees -- [page:Float]
  27. </div>
  28. <div>
  29. Converts degrees to radians.
  30. </div>
  31. <h3>[method:Integer euclideanModulo]( [page:Integer n], [page:Integer m] )</h3>
  32. <div>
  33. n, m --Integers
  34. </div>
  35. <div>
  36. Compute the Euclidian modulo of m % n, that is:
  37. <code>( ( n % m ) + m ) % m</code>
  38. </div>
  39. <h3>[method:UUID generateUUID]( )</h3>
  40. <div>
  41. Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID] (universally unique identifier).
  42. </div>
  43. <h3>[method:Boolean isPowerOfTwo]( n )</h3>
  44. <div>
  45. Return *true* if n is a power of 2.
  46. </div>
  47. <h3>[method:Float lerp]( [page:Float x], [page:Float y], [page:Float t] )</h3>
  48. <div>
  49. x -- Start point. <br />
  50. y -- End point. <br />
  51. t -- Closed unit interval from [0,1].
  52. </div>
  53. <div>
  54. Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated] from two known points based on the given interval.
  55. </div>
  56. <h3>[method:Float mapLinear]( [page:Float x], [page:Float a1], [page:Float a2], [page:Float b1], [page:Float b2] )</h3>
  57. <div>
  58. x — Value to be mapped.<br />
  59. a1 — Minimum value for range A.<br />
  60. a2 — Maximum value for range A.<br />
  61. b1 — Minimum value for range B.<br />
  62. b2 — Maximum value for range B.
  63. </div>
  64. <div>
  65. Linear mapping of *x* from range [*a1*, *a2*] to range [*b1*, *b2*].
  66. </div>
  67. <h3>[method:Integer nearestPowerOfTwo]( n )</h3>
  68. <div>
  69. Return the nearest power of 2 to a given number n.
  70. </div>
  71. <h3>[method:Integer nextPowerOfTwo]( n )</h3>
  72. <div>
  73. Return the nearest power of 2 that is bigger than n.
  74. </div>
  75. <h3>[method:Float radToDeg]( [page:Float radians] )</h3>
  76. <div>
  77. radians -- [page:Float]
  78. </div>
  79. <div>
  80. Converts radians to degrees
  81. </div>
  82. <h3>[method:Float randFloat]( [page:Float low], [page:Float high] )</h3>
  83. <div>
  84. Random float from *low* to *high* interval.
  85. </div>
  86. <h3>[method:Float randFloatSpread]( [page:Float range] )</h3>
  87. <div>
  88. Random float from *- range / 2* to *range / 2* interval.
  89. </div>
  90. <h3>[method:Integer randInt]( [page:Integer low], [page:Integer high] )</h3>
  91. <div>
  92. Random integer from *low* to *high* interval.
  93. </div>
  94. <h3>[method:Float random16]()</h3>
  95. <div>
  96. Random float from 0 to 1 with 16 bits of randomness.<br />
  97. Standard Math.random() creates repetitive patterns when applied over larger space.
  98. </div>
  99. <h3>[method:Float smoothstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
  100. <div>
  101. x -- The value to evaluate based on its position between min and max. <br />
  102. min -- Any x value below min will be 0 <br />
  103. max -- Any x value above max will be 1
  104. </div>
  105. <div>
  106. Returns a value between 0-1 that represents the percentage that x has moved between min and max,
  107. but smoothed or slowed down the closer X is to the min and max.<br/><br/>
  108. [link:http://en.wikipedia.org/wiki/Smoothstep Wikipedia]
  109. </div>
  110. <h3>[method:Float smootherstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
  111. <div>
  112. x -- The value to evaluate based on its position between min and max. <br />
  113. min -- Any x value below min will be 0 <br />
  114. max -- Any x value above max will be 1
  115. </div>
  116. <div>
  117. Returns a value between 0-1. It works the same as smoothstep, but more smooth.
  118. </div>
  119. <h2>Source</h2>
  120. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  121. </body>
  122. </html>