1
0

MathUtils.html 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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>
  14. [method:Float clamp]( [param:Float value], [param:Float min], [param:Float max] )
  15. </h3>
  16. <p>
  17. [page:Float value] — Value to be clamped.<br />
  18. [page:Float min] — Minimum value.<br />
  19. [page:Float max] — Maximum value.<br /><br />
  20. Clamps the [page:Float value] to be between [page:Float min] and
  21. [page:Float max].
  22. </p>
  23. <h3>[method:Float degToRad]( [param:Float degrees] )</h3>
  24. <p>Converts degrees to radians.</p>
  25. <h3>
  26. [method:Integer euclideanModulo]( [param:Integer n], [param:Integer m] )
  27. </h3>
  28. <p>
  29. [page:Integer n], [page:Integer m] - Integers<br /><br />
  30. Computes the Euclidean modulo of [page:Integer m] % [page:Integer n], that
  31. is:
  32. <code>( ( n % m ) + m ) % m</code>
  33. </p>
  34. <h3>[method:UUID generateUUID]( )</h3>
  35. <p>
  36. Generate a
  37. [link:https://en.wikipedia.org/wiki/Universally_unique_identifier UUID]
  38. (universally unique identifier).
  39. </p>
  40. <h3>[method:Boolean isPowerOfTwo]( [param:Number n] )</h3>
  41. <p>Return `true` if [page:Number n] is a power of 2.</p>
  42. <h3>
  43. [method:Float inverseLerp]( [param:Float x], [param:Float y], [param:Float value] )
  44. </h3>
  45. <p>
  46. [page:Float x] - Start point.<br />
  47. [page:Float y] - End point.<br />
  48. [page:Float value] - A value between start and end.<br /><br />
  49. Returns the percentage in the closed interval `[0, 1]` of the given value
  50. between the start and end point.
  51. </p>
  52. <h3>
  53. [method:Float lerp]( [param:Float x], [param:Float y], [param:Float t] )
  54. </h3>
  55. <p>
  56. [page:Float x] - Start point. <br />
  57. [page:Float y] - End point. <br />
  58. [page:Float t] - interpolation factor in the closed interval `[0, 1]`.<br /><br />
  59. Returns a value [link:https://en.wikipedia.org/wiki/Linear_interpolation linearly interpolated]
  60. from two known points based on the given interval -
  61. [page:Float t] = 0 will return [page:Float x] and [page:Float t] = 1 will
  62. return [page:Float y].
  63. </p>
  64. <h3>
  65. [method:Float damp]( [param:Float x], [param:Float y], [param:Float lambda], [param:Float dt] )
  66. </h3>
  67. <p>
  68. [page:Float x] - Current point. <br />
  69. [page:Float y] - Target point. <br />
  70. [page:Float lambda] - A higher lambda value will make the movement more
  71. sudden, and a lower value will make the movement more gradual. <br />
  72. [page:Float dt] - Delta time in seconds.<br /><br />
  73. Smoothly interpolate a number from [page:Float x] toward [page:Float y] in
  74. a spring-like manner using the [page:Float dt] to maintain frame rate
  75. independent movement. For details, see
  76. [link:http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/ Frame rate independent damping using lerp].
  77. </p>
  78. <h3>
  79. [method:Float mapLinear]( [param:Float x], [param:Float a1], [param:Float a2], [param:Float b1], [param:Float b2] )
  80. </h3>
  81. <p>
  82. [page:Float x] — Value to be mapped.<br />
  83. [page:Float a1] — Minimum value for range A.<br />
  84. [page:Float a2] — Maximum value for range A.<br />
  85. [page:Float b1] — Minimum value for range B.<br />
  86. [page:Float b2] — Maximum value for range B.<br /><br />
  87. Linear mapping of [page:Float x] from range [[page:Float a1], [page:Float a2]] to range [[page:Float b1], [page:Float b2]].
  88. </p>
  89. <h3>[method:Float pingpong]( [param:Float x], [param:Float length] )</h3>
  90. <p>
  91. [page:Float x] — The value to pingpong.<br />
  92. [page:Float length] — The positive value the function will pingpong to.
  93. Default is `1`.<br /><br />
  94. Returns a value that alternates between `0` and [param:Float length].
  95. </p>
  96. <h3>[method:Integer ceilPowerOfTwo]( [param:Number n] )</h3>
  97. <p>
  98. Returns the smallest power of 2 that is greater than or equal to
  99. [page:Number n].
  100. </p>
  101. <h3>[method:Integer floorPowerOfTwo]( [param:Number n] )</h3>
  102. <p>
  103. Returns the largest power of `2` that is less than or equal to [page:Number n].
  104. </p>
  105. <h3>[method:Float radToDeg]( [param:Float radians] )</h3>
  106. <p>Converts radians to degrees.</p>
  107. <h3>[method:Float randFloat]( [param:Float low], [param:Float high] )</h3>
  108. <p>Random float in the interval [[page:Float low], [page:Float high]].</p>
  109. <h3>[method:Float randFloatSpread]( [param:Float range] )</h3>
  110. <p>
  111. Random float in the interval [- [page:Float range] / 2, [page:Float range]
  112. / 2].
  113. </p>
  114. <h3>
  115. [method:Integer randInt]( [param:Integer low], [param:Integer high] )
  116. </h3>
  117. <p>Random integer in the interval [[page:Float low], [page:Float high]].</p>
  118. <h3>[method:Float seededRandom]( [param:Integer seed] )</h3>
  119. <p>
  120. Deterministic pseudo-random float in the interval `[0, 1]`. The integer
  121. [page:Integer seed] is optional.
  122. </p>
  123. <h3>
  124. [method:Float smoothstep]( [param:Float x], [param:Float min], [param:Float max] )
  125. </h3>
  126. <p>
  127. [page:Float x] - The value to evaluate based on its position between min
  128. and max. <br />
  129. [page:Float min] - Any x value below min will be `0`.<br />
  130. [page:Float max] - Any x value above max will be `1`.<br /><br />
  131. Returns a value between 0-1 that represents the percentage that x has
  132. moved between min and max, but smoothed or slowed down the closer X is to
  133. the min and max.<br /><br />
  134. See [link:http://en.wikipedia.org/wiki/Smoothstep Smoothstep] for details.
  135. </p>
  136. <h3>
  137. [method:Float smootherstep]( [param:Float x], [param:Float min], [param:Float max] )
  138. </h3>
  139. <p>
  140. [page:Float x] - The value to evaluate based on its position between min
  141. and max. <br />
  142. [page:Float min] - Any x value below min will be `0`.<br />
  143. [page:Float max] - Any x value above max will be `1`.<br /><br />
  144. Returns a value between 0-1. A
  145. [link:https://en.wikipedia.org/wiki/Smoothstep#Variations variation on smoothstep]
  146. that has zero 1st and 2nd order derivatives at x=0 and x=1.
  147. </p>
  148. <h3>
  149. [method:undefined setQuaternionFromProperEuler]( [param:Quaternion q], [param:Float a], [param:Float b], [param:Float c], [param:String order] )
  150. </h3>
  151. <p>
  152. [page:Quaternion q] - the quaternion to be set<br />
  153. [page:Float a] - the rotation applied to the first axis, in radians <br />
  154. [page:Float b] - the rotation applied to the second axis, in radians
  155. <br />
  156. [page:Float c] - the rotation applied to the third axis, in radians <br />
  157. [page:String order] - a string specifying the axes order: 'XYX', 'XZX',
  158. 'YXY', 'YZY', 'ZXZ', or 'ZYZ'<br /><br />
  159. Sets quaternion [page:Quaternion q] from the
  160. [link:http://en.wikipedia.org/wiki/Euler_angles intrinsic Proper Euler Angles]
  161. defined by angles [page:Float a], [page:Float b], and [page:Float c],
  162. and order [page:String order].<br />
  163. Rotations are applied to the axes in the order specified by [page:String order]:
  164. rotation by angle [page:Float a] is applied first, then by angle
  165. [page:Float b], then by angle [page:Float c]. Angles are in radians.
  166. </p>
  167. <h2>Source</h2>
  168. <p>
  169. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  170. </p>
  171. </body>
  172. </html>