MathUtils.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="page.js"></script>
  7. <link type="text/css" rel="stylesheet" href="page.css" />
  8. </head>
  9. <body>
  10. <h1>[name]</h1>
  11. <p class="desc">An object with several math utility functions.</p>
  12. <h2>Functions</h2>
  13. <h3>[method:Float clamp]( [param:Float value], [param:Float min], [param:Float max] )</h3>
  14. <p>
  15. [page:Float value] — Value to be clamped.<br />
  16. [page:Float min] — Minimum value.<br />
  17. [page:Float max] — Maximum value.<br /><br />
  18. Clamps the [page:Float value] to be between [page:Float min] and [page:Float max].
  19. </p>
  20. <h3>[method:Float degToRad]( [param:Float degrees] )</h3>
  21. <p>Converts degrees to radians.</p>
  22. <h3>[method:Integer euclideanModulo]( [param:Integer n], [param:Integer m] )</h3>
  23. <p>
  24. [page:Integer n], [page:Integer m] - Integers<br /><br />
  25. Computes the Euclidean modulo of [page:Integer m] % [page:Integer n], that is:
  26. <code>( ( n % m ) + m ) % m</code>
  27. </p>
  28. <h3>[method:UUID generateUUID]( )</h3>
  29. <p>
  30. Generate a [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID]
  31. (universally unique identifier).
  32. </p>
  33. <h3>[method:Boolean isPowerOfTwo]( [param:Number n] )</h3>
  34. <p>Return *true* if [page:Number n] is a power of 2.</p>
  35. <h3>[method:Float lerp]( [param:Float x], [param:Float y], [param:Float t] )</h3>
  36. <p>
  37. [page:Float x] - Start point. <br />
  38. [page:Float y] - End point. <br />
  39. [page:Float t] - interpolation factor in the closed interval [0, 1].<br><br />
  40. Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated]
  41. from two known points based on the given interval - [page:Float t] = 0 will return [page:Float x]
  42. and [page:Float t] = 1 will return [page:Float y].
  43. </p>
  44. <h3>[method:Float mapLinear]( [param:Float x], [param:Float a1], [param:Float a2], [param:Float b1], [param:Float b2] )</h3>
  45. <p>
  46. [page:Float x] — Value to be mapped.<br />
  47. [page:Float a1] — Minimum value for range A.<br />
  48. [page:Float a2] — Maximum value for range A.<br />
  49. [page:Float b1] — Minimum value for range B.<br />
  50. [page:Float b2] — Maximum value for range B.<br /><br />
  51. Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
  52. </p>
  53. <h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
  54. <p>Returns the smallest power of 2 that is greater than or equal to [page:Number n].</p>
  55. <h3>[method:Integer floorPowerOfTwo]( [param:Number n] )</h3>
  56. <p>Returns the largest power of 2 that is less than or equal to [page:Number n].</p>
  57. <h3>[method:Float radToDeg]( [param:Float radians] )</h3>
  58. <p>Converts radians to degrees.</p>
  59. <h3>[method:Float randFloat]( [param:Float low], [param:Float high] )</h3>
  60. <p>Random float in the interval [[page:Float low], [page:Float high]].</p>
  61. <h3>[method:Float randFloatSpread]( [param:Float range] )</h3>
  62. <p>Random float in the interval [- [page:Float range] / 2, [page:Float range] / 2].</p>
  63. <h3>[method:Integer randInt]( [param:Integer low], [param:Integer high] )</h3>
  64. <p>Random integer in the interval [[page:Float low], [page:Float high]].</p>
  65. <h3>[method:Float seededRandom]( [param:Integer seed] )</h3>
  66. <p>Deterministic pseudo-random float in the interval [0, 1]. The integer [page:Integer seed] is optional.</p>
  67. <h3>[method:Float smoothstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  68. <p>
  69. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  70. [page:Float min] - Any x value below min will be 0.<br />
  71. [page:Float max] - Any x value above max will be 1.<br /><br />
  72. Returns a value between 0-1 that represents the percentage that x has moved between min and max,
  73. but smoothed or slowed down the closer X is to the min and max.<br/><br/>
  74. See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
  75. </p>
  76. <h3>[method:Float smootherstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  77. <p>
  78. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  79. [page:Float min] - Any x value below min will be 0.<br />
  80. [page:Float max] - Any x value above max will be 1.<br /><br />
  81. Returns a value between 0-1. A [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
  82. that has zero 1st and 2nd order derivatives at x=0 and x=1.
  83. </p>
  84. <h3>[method:null setQuaternionFromProperEuler]( [param:Quaternion q], [param:Float a], [param:Float b], [param:Float c], [param:String order] )</h3>
  85. <p>
  86. [page:Quaternion q] - the quaternion to be set<br />
  87. [page:Float a] - the rotation applied to the first axis, in radians <br />
  88. [page:Float b] - the rotation applied to the second axis, in radians <br />
  89. [page:Float c] - the rotation applied to the third axis, in radians <br />
  90. [page:String order] - a string specifying the axes order: 'XYX', 'XZX', 'YXY', 'YZY', 'ZXZ', or 'ZYZ'<br /><br />
  91. 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 />
  92. 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.
  93. </p>
  94. <h2>Source</h2>
  95. <p>
  96. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  97. </p>
  98. </body>
  99. </html>