2
0

MathUtils.html 6.9 KB

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