MathUtils.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 damp]( [param:Float x], [param:Float y], [param:Float lambda], [param:Float dt] )</h3>
  45. <p>
  46. [page:Float x] - Current point. <br />
  47. [page:Float y] - Target point. <br />
  48. [page:Float lambda] - A higher lambda value will make the movement more sudden, and a lower value will make the movement more gradual. <br />
  49. [page:Float dt] - Delta time in seconds.<br><br />
  50. Smoothly interpolate a number from [page:Float x] toward [page:Float y] in a spring-like manner using the [page:Float dt] to maintain frame rate independent movement.
  51. For details, see [link:http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ Frame rate independent damping using lerp].
  52. </p>
  53. <h3>[method:Float mapLinear]( [param:Float x], [param:Float a1], [param:Float a2], [param:Float b1], [param:Float b2] )</h3>
  54. <p>
  55. [page:Float x] — Value to be mapped.<br />
  56. [page:Float a1] — Minimum value for range A.<br />
  57. [page:Float a2] — Maximum value for range A.<br />
  58. [page:Float b1] — Minimum value for range B.<br />
  59. [page:Float b2] — Maximum value for range B.<br /><br />
  60. Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
  61. </p>
  62. <h3>[method:Float pingpong]( [param:Float x], [param:Float length] )</h3>
  63. <p>
  64. [page:Float x] — The value to pingpong.<br />
  65. [page:Float length] — The positive value the function will pingpong to. Default is 1.<br /><br />
  66. Returns a value that alternates between 0 and [param:Float length].</p>
  67. <h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
  68. <p>Returns the smallest power of 2 that is greater than or equal to [page:Number n].</p>
  69. <h3>[method:Integer floorPowerOfTwo]( [param:Number n] )</h3>
  70. <p>Returns the largest power of 2 that is less than or equal to [page:Number n].</p>
  71. <h3>[method:Float radToDeg]( [param:Float radians] )</h3>
  72. <p>Converts radians to degrees.</p>
  73. <h3>[method:Float randFloat]( [param:Float low], [param:Float high] )</h3>
  74. <p>Random float in the interval [[page:Float low], [page:Float high]].</p>
  75. <h3>[method:Float randFloatSpread]( [param:Float range] )</h3>
  76. <p>Random float in the interval [- [page:Float range] / 2, [page:Float range] / 2].</p>
  77. <h3>[method:Integer randInt]( [param:Integer low], [param:Integer high] )</h3>
  78. <p>Random integer in the interval [[page:Float low], [page:Float high]].</p>
  79. <h3>[method:Float seededRandom]( [param:Integer seed] )</h3>
  80. <p>Deterministic pseudo-random float in the interval [0, 1]. The integer [page:Integer seed] is optional.</p>
  81. <h3>[method:Float smoothstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  82. <p>
  83. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  84. [page:Float min] - Any x value below min will be 0.<br />
  85. [page:Float max] - Any x value above max will be 1.<br /><br />
  86. Returns a value between 0-1 that represents the percentage that x has moved between min and max,
  87. but smoothed or slowed down the closer X is to the min and max.<br/><br/>
  88. See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
  89. </p>
  90. <h3>[method:Float smootherstep]( [param:Float x], [param:Float min], [param:Float max] )</h3>
  91. <p>
  92. [page:Float x] - The value to evaluate based on its position between min and max. <br />
  93. [page:Float min] - Any x value below min will be 0.<br />
  94. [page:Float max] - Any x value above max will be 1.<br /><br />
  95. Returns a value between 0-1. A [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
  96. that has zero 1st and 2nd order derivatives at x=0 and x=1.
  97. </p>
  98. <h3>[method:null setQuaternionFromProperEuler]( [param:Quaternion q], [param:Float a], [param:Float b], [param:Float c], [param:String order] )</h3>
  99. <p>
  100. [page:Quaternion q] - the quaternion to be set<br />
  101. [page:Float a] - the rotation applied to the first axis, in radians <br />
  102. [page:Float b] - the rotation applied to the second axis, in radians <br />
  103. [page:Float c] - the rotation applied to the third axis, in radians <br />
  104. [page:String order] - a string specifying the axes order: 'XYX', 'XZX', 'YXY', 'YZY', 'ZXZ', or 'ZYZ'<br /><br />
  105. 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 />
  106. 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.
  107. </p>
  108. <h2>Source</h2>
  109. <p>
  110. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  111. </p>
  112. </body>
  113. </html>