Vector2.html 8.5 KB

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