2
0

Math.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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">An object with several math utility functions.</div>
  13. <h2>Functions</h2>
  14. <h3>[method:Float clamp]( [page:Float value], [page:Float min], [page:Float max] )</h3>
  15. <div>
  16. [page:Float value] — Value to be clamped.<br />
  17. [page:Float min] — Minimum value.<br />
  18. [page:Float max] — Maximum value.<br /><br />
  19. Clamps the [page:Float value] to be between [page:Float min] and [page:Float max].
  20. </div>
  21. <h3>[method:Float degToRad]( [page:Float degrees] )</h3>
  22. <div>Converts degrees to radians.</div>
  23. <h3>[method:Integer euclideanModulo]( [page:Integer n], [page:Integer m] )</h3>
  24. <div>
  25. [page:Integer n], [page:Integer m] - Integers<br /><br />
  26. Compute the Euclidean modulo of m % [page:Integer n], that is:
  27. <code>( ( n % m ) + m ) % m</code>
  28. </div>
  29. <h3>[method:UUID generateUUID]( )</h3>
  30. <div>
  31. Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID]
  32. (universally unique identifier).
  33. </div>
  34. <h3>[method:Boolean isPowerOfTwo]( [page:Number n] )</h3>
  35. <div>Return *true* if [page:Number n] is a power of 2.</div>
  36. <h3>[method:Float lerp]( [page:Float x], [page:Float y], [page:Float t] )</h3>
  37. <div>
  38. [page:Float x] - Start point. <br />
  39. [page:Float y] - End point. <br />
  40. [page:Float t] - interpolation factor in the closed interval [0, 1].<br><br />
  41. Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated]
  42. from two known points based on the given interval - [page:Float t] = 0 will return [page:Float x]
  43. and [page:Float t] = 1 will return [page:Float y].
  44. </div>
  45. <h3>[method:Float mapLinear](
  46. [page:Float x],
  47. [page:Float a1],
  48. [page:Float a2],
  49. [page:Float b1],
  50. [page:Float b2] )</h3>
  51. <div>
  52. [page:Float x] — Value to be mapped.<br />
  53. [page:Float a1] — Minimum value for range A.<br />
  54. [page:Float a2] — Maximum value for range A.<br />
  55. [page:Float b1] — Minimum value for range B.<br />
  56. [page:Float b2] — Maximum value for range B.<br /><br />
  57. Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
  58. </div>
  59. <h3>[method:Integer nearestPowerOfTwo]( [page:Number n] )</h3>
  60. <div> Return the nearest power of 2 to a given number [page:Number n].</div>
  61. <h3>[method:Integer nextPowerOfTwo]( [page:Number n] )</h3>
  62. <div>Return the nearest power of 2 that is bigger than [page:Number n].</div>
  63. <h3>[method:Float radToDeg]( [page:Float radians] )</h3>
  64. <div>Converts radians to degrees.</div>
  65. <h3>[method:Float randFloat]( [page:Float low], [page:Float high] )</h3>
  66. <div>Random float in the interval [page:Float low] to [page:Float high].</div>
  67. <h3>[method:Float randFloatSpread]( [page:Float range] )</h3>
  68. <div>Random float in the intercal *- [page:Float range] / 2* to *[page:Float range] / 2*.</div>
  69. <h3>[method:Integer randInt]( [page:Integer low], [page:Integer high] )</h3>
  70. <div>Random integer in the interval [page:Float low] to [page:Float high].</div>
  71. <h3>[method:Float smoothstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
  72. <div>
  73. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  74. [page:Float min] - Any x value below min will be 0.<br />
  75. [page:Float max] - Any x value above max will be 1.<br /><br />
  76. Returns a value between 0-1 that represents the percentage that x has moved between min and max,
  77. but smoothed or slowed down the closer X is to the min and max.<br/><br/>
  78. See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
  79. </div>
  80. <h3>[method:Float smootherstep]( [page:Float x], [page:Float min], [page:Float max] )</h3>
  81. <div>
  82. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  83. [page:Float min] - Any x value below min will be 0.<br />
  84. [page:Float max] - Any x value above max will be 1.<br /><br />
  85. Returns a value between 0-1. A [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
  86. that has zero 1st and 2nd order derivatives at x=0 and x=1.
  87. </div>
  88. <h2>Source</h2>
  89. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  90. </body>
  91. </html>