Vector2.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <script src="../../list.js"></script>
  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. <div class="desc">2D vector.</div>
  12. <h2>Example</h2>
  13. <code>var a = new THREE.Vector2( 0, 1 );
  14. var b = new THREE.Vector2( 1, 0 );
  15. var d = a.distanceTo( b );
  16. </code>
  17. <h2>Constructor</h2>
  18. <h3>[name]( [page:Float x], [page:Float y] )</h3>
  19. <div>
  20. x -- [page:Float] representing the x value of the vector <br />
  21. y -- [page:Float] representing the y value of the vector
  22. </div>
  23. <div>
  24. A vector in 2 dimensional space
  25. </div>
  26. <h2>Properties</h2>
  27. <h3>.[page:Float x]</h3>
  28. <h3>.[page:Float y]</h3>
  29. <h2>Methods</h2>
  30. <h3>.set( [page:Float x], [page:Float y] ) [page:Vector2 this]</h3>
  31. <div>
  32. Sets value of this vector.
  33. </div>
  34. <h3>.copy( [page:Vector2 v] ) [page:Vector2 this]</h3>
  35. <div>
  36. Copies value of *v* to this vector.
  37. </div>
  38. <h3>.add( [page:Vector2 v] ) [page:Vector2 this]</h3>
  39. <div>
  40. Adds *v* to this vector.
  41. </div>
  42. <h3>.addVectors( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
  43. <div>
  44. Sets this vector to *a + b*.
  45. </div>
  46. <h3>.sub( [page:Vector2 v] ) [page:Vector2 this]</h3>
  47. <div>
  48. Subtracts *v* from this vector.
  49. </div>
  50. <h3>.subVectors( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
  51. <div>
  52. Sets this vector to *a - b*.
  53. </div>
  54. <h3>.multiplyScalar( [page:Float s] ) [page:Vector2 this]</h3>
  55. <div>
  56. Multiplies this vector by scalar *s*.
  57. </div>
  58. <h3>.divideScalar( [page:Float s] ) [page:Vector2 this]</h3>
  59. <div>
  60. Divides this vector by scalar *s*.<br />
  61. Set vector to *( 0, 0 )* if *s == 0*.
  62. </div>
  63. <h3>.negate() [page:Vector2 this]</h3>
  64. <div>
  65. Inverts this vector.
  66. </div>
  67. <h3>.dot( [page:Vector2 v] ) [page:Float]</h3>
  68. <div>
  69. Computes dot product of this vector and *v*.
  70. </div>
  71. <h3>.lengthSq() [page:Float]</h3>
  72. <div>
  73. Computes squared length of this vector.
  74. </div>
  75. <h3>.length() [page:Float]</h3>
  76. <div>
  77. Computes length of this vector.
  78. </div>
  79. <h3>.normalize() [page:Vector2 this]</h3>
  80. <div>
  81. Normalizes this vector.
  82. </div>
  83. <h3>.distanceTo( [page:Vector2 v] ) [page:Float]</h3>
  84. <div>
  85. Computes distance of this vector to *v*.
  86. </div>
  87. <h3>.distanceToSquared( [page:Vector2 v] ) [page:Float]</h3>
  88. <div>
  89. Computes squared distance of this vector to *v*.
  90. </div>
  91. <h3>.setLength( [page:Float l] ) [page:Vector2 this]</h3>
  92. <div>
  93. Normalizes this vector and multiplies it by *l*.
  94. </div>
  95. <h3>.equals( [page:Vector2 v] ) [page:Boolean]</h3>
  96. <div>
  97. Checks for strict equality of this vector and *v*.
  98. </div>
  99. <h3>.clone() [page:Vector2]</h3>
  100. <div>
  101. Clones this vector.
  102. </div>
  103. <h3>.clamp([page:Vector2 min], [page:Vector2 max]) [page:Vector2 this]</h3>
  104. <div>
  105. min -- [page:Vector2] containing the min x and y values in the desired range <br />
  106. max -- [page:Vector2] containing the max x and y values in the desired range
  107. </div>
  108. <div>
  109. If this vector's x or y value is greater than the max vector's x or y value, it is replaced by the corresponding value. <br /> If this vector's x or y value is less than the min vector's x or y value, it is replace by the corresponding value.
  110. </div>
  111. <h3>.clampScalar([page:Float min], [page:Float max]) [page:Vector2 this]</h3>
  112. <div>
  113. min -- [page:Float] the minimum value the components will be clamped to <br />
  114. max -- [page:Float] the maximum value the components will be clamped to
  115. </div>
  116. <div>
  117. If this vector's x or y values are greater than the max value, they are replaced by the max value. <br /> If this vector's x or y values are less than the min value, they are replace by the min value.
  118. </div>
  119. <h3>.floor() [page:Vector2]</h3>
  120. <div>
  121. The components of the vector are rounded downwards (towards negative infinity) to an integer value.
  122. </div>
  123. <h3>.ceil() [page:Vector2]</h3>
  124. <div>
  125. The components of the vector are rounded upwards (towards positive infinity) to an integer value.
  126. </div>
  127. <h3>.round() [page:Vector2]</h3>
  128. <div>
  129. The components of the vector are rounded towards the nearest integer value.
  130. </div>
  131. <h3>.roundToZero() [page:Vector2]</h3>
  132. <div>
  133. The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
  134. </div>
  135. <h3>.lerp([page:Vector2 v], [page:Float alpha]) [page:Vector2 this]</h3>
  136. <div>
  137. v -- [page:Vector2] <br />
  138. alpha -- [page:Float] between 0 and 1;
  139. </div>
  140. <div>
  141. Linear interpolation between this vector and v, where alpha is the percent along the line.
  142. </div>
  143. <h3>.setComponent([page:Integer index], [page:Float value]) [page:undefined]</h3>
  144. <div>
  145. index -- 0 or 1 <br />
  146. value -- [page:Float]
  147. </div>
  148. <div>
  149. if index equals 0 method replaces this.x with value. <br />
  150. if index equals 1 method replaces this.y with value.
  151. </div>
  152. <h3>.addScalar([page:Float s]) [page:Vector2 this]</h3>
  153. <div>
  154. s -- [page:Float]
  155. </div>
  156. <div>
  157. Add the scalar value s to this vector's x and y values.
  158. </div>
  159. <h3>.getComponent([page:Integer index]) [page:Float]</h3>
  160. <div>
  161. index -- 0 or 1
  162. </div>
  163. <div>
  164. if index equals 0 returns the x value. <br />
  165. if index equals 1 returns the y value.
  166. </div>
  167. <h3>.fromArray([page:Array array]) [page:Vector2 this]</h3>
  168. <div>
  169. array -- [page:Array] of length 2
  170. </div>
  171. <div>
  172. Sets this vector's x value to be array[0] and y value to be array[1].
  173. </div>
  174. <h3>.toArray() [page:Array]</h3>
  175. <div>
  176. Returns an array [x, y].
  177. </div>
  178. <h3>.min([page:Vector2 v]) [page:Vector2 this]</h3>
  179. <div>
  180. v -- [page:Vector2]
  181. </div>
  182. <div>
  183. If this vector's x or y value is less than v's x or y value, replace that value with the corresponding min value.
  184. </div>
  185. <h3>.max([page:Vector2 v]) [page:Vector2 this]</h3>
  186. <div>
  187. v -- [page:Vector2]
  188. </div>
  189. <div>
  190. If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding max value.
  191. </div>
  192. <h3>.setX([page:Float x]) [page:Vector2 this]</h3>
  193. <div>
  194. x -- [page:Float]
  195. </div>
  196. <div>
  197. replace this vector's x value with x.
  198. </div>
  199. <h3>.setY([page:Float y]) [page:Vector2 this]</h3>
  200. <div>
  201. y -- [page:Float]
  202. </div>
  203. <div>
  204. replace this vector's y value with y.
  205. </div>
  206. <h2>Source</h2>
  207. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  208. </body>
  209. </html>