MathUtils.html 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. <p class="desc">An object with several math utility functions.</p>
  13. <h2>Functions</h2>
  14. <h3>[method:Float clamp]( [param:Float value], [param:Float min], [param:Float max] )</h3>
  15. <p>
  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. </p>
  21. <h3>[method:Float degToRad]( [param:Float degrees] )</h3>
  22. <p>Converts degrees to radians.</p>
  23. <h3>[method:Integer euclideanModulo]( [param:Integer n], [param:Integer m] )</h3>
  24. <p>
  25. [page:Integer n], [page:Integer m] - Integers<br /><br />
  26. Computes the Euclidean modulo of [page:Integer m] % [page:Integer n], that is:
  27. <code>( ( n % m ) + m ) % m</code>
  28. </p>
  29. <h3>[method:UUID generateUUID]( )</h3>
  30. <p>
  31. Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID]
  32. (universally unique identifier).
  33. </p>
  34. <h3>[method:Boolean isPowerOfTwo]( [param:Number n] )</h3>
  35. <p>Return *true* if [page:Number n] is a power of 2.</p>
  36. <h3>[method:Float lerp]( [param:Float x], [param:Float y], [param:Float t] )</h3>
  37. <p>
  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. </p>
  45. <h3>[method:Float mapLinear]( [param:Float x], [param:Float a1], [param:Float a2], [param:Float b1], [param:Float b2] )</h3>
  46. <p>
  47. [page:Float x] — Value to be mapped.<br />
  48. [page:Float a1] — Minimum value for range A.<br />
  49. [page:Float a2] — Maximum value for range A.<br />
  50. [page:Float b1] — Minimum value for range B.<br />
  51. [page:Float b2] — Maximum value for range B.<br /><br />
  52. Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
  53. </p>
  54. <h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
  55. <p>Returns the smallest power of 2 that is greater than or equal to [page:Number n].</p>
  56. <h3>[method:Integer floorPowerOfTwo]( [param:Number n] )</h3>
  57. <p>Returns the largest power of 2 that is less than or equal to [page:Number n].</p>
  58. <h3>[method:Float radToDeg]( [param:Float radians] )</h3>
  59. <p>Converts radians to degrees.</p>
  60. <h3>[method:Float randFloat]( [param:Float low], [param:Float high] )</h3>
  61. <p>Random float in the interval [page:Float low] to [page:Float high].</p>
  62. <h3>[method:Float randFloatSpread]( [param:Float range] )</h3>
  63. <p>Random float in the interval *- [page:Float range] / 2* to *[page:Float range] / 2*.</p>
  64. <h3>[method:Integer randInt]( [param:Integer low], [param:Integer high] )</h3>
  65. <p>Random integer in the interval [page:Float low] to [page:Float high].</p>
  66. <h3>[method:Float smoothstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  67. <p>
  68. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  69. [page:Float min] - Any x value below min will be 0.<br />
  70. [page:Float max] - Any x value above max will be 1.<br /><br />
  71. Returns a value between 0-1 that represents the percentage that x has moved between min and max,
  72. but smoothed or slowed down the closer X is to the min and max.<br/><br/>
  73. See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
  74. </p>
  75. <h3>[method:Float smootherstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  76. <p>
  77. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  78. [page:Float min] - Any x value below min will be 0.<br />
  79. [page:Float max] - Any x value above max will be 1.<br /><br />
  80. Returns a value between 0-1. A [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
  81. that has zero 1st and 2nd order derivatives at x=0 and x=1.
  82. </p>
  83. <h3>[method:null setQuaternionFromProperEuler]( [param:Quaternion q], [param:Float a], [param:Float b], [param:Float c], [param:String order] )</h3>
  84. <p>
  85. [page:Quaternion q] - the quaternion to be set<br />
  86. [page:Float a] - the rotation applied to the first axis, in radians <br />
  87. [page:Float b] - the rotation applied to the second axis, in radians <br />
  88. [page:Float c] - the rotation applied to the third axis, in radians <br />
  89. [page:String order] - a string specifying the axes order: 'XYX', 'XZX', 'YXY', 'YZY', 'ZXZ', or 'ZYZ'<br /><br />
  90. Sets quaternion [page:Quaternion q] from the [link:http://en.wikipedia.org/wiki/Euler_angles intrinsic Proper Euler Angles] defined by angles [page:Float a], [page:Float b], and [page:Float c], and order [page:String order].<br />
  91. Rotations are applied to the axes in the order specified by [page:String order]: rotation by angle [page:Float a] is applied first, then by angle [page:Float b], then by angle [page:Float c]. Angles are in radians.
  92. </p>
  93. <h2>Source</h2>
  94. <p>
  95. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  96. </p>
  97. </body>
  98. </html>