Vector2.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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>[property:Float x]</h3>
  28. <h3>[property:Float y]</h3>
  29. <h2>Methods</h2>
  30. <h3>[method:Vector2 set]( [page:Float x], [page:Float y] ) [page:Vector2 this]</h3>
  31. <div>
  32. Sets value of this vector.
  33. </div>
  34. <h3>[method:Vector2 copy]( [page:Vector2 v] ) [page:Vector2 this]</h3>
  35. <div>
  36. Copies value of *v* to this vector.
  37. </div>
  38. <h3>[method:Vector2 add]( [page:Vector2 v] ) [page:Vector2 this]</h3>
  39. <div>
  40. Adds *v* to this vector.
  41. </div>
  42. <h3>[method:Vector2 addVectors]( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
  43. <div>
  44. Sets this vector to *a + b*.
  45. </div>
  46. <h3>[method:Vector2 sub]( [page:Vector2 v] ) [page:Vector2 this]</h3>
  47. <div>
  48. Subtracts *v* from this vector.
  49. </div>
  50. <h3>[method:Vector2 subVectors]( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]</h3>
  51. <div>
  52. Sets this vector to *a - b*.
  53. </div>
  54. <h3>[method:Vector2 multiplyScalar]( [page:Float s] ) [page:Vector2 this]</h3>
  55. <div>
  56. Multiplies this vector by scalar *s*.
  57. </div>
  58. <h3>[method:Vector2 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>[method:Vector2 negate]() [page:Vector2 this]</h3>
  64. <div>
  65. Inverts this vector.
  66. </div>
  67. <h3>[method:Float dot]( [page:Vector2 v] )</h3>
  68. <div>
  69. Computes dot product of this vector and *v*.
  70. </div>
  71. <h3>[method:Float lengthSq]()</h3>
  72. <div>
  73. Computes squared length of this vector.
  74. </div>
  75. <h3>[method:Float length]()</h3>
  76. <div>
  77. Computes length of this vector.
  78. </div>
  79. <h3>[method:Float lengthManhattan]()</h3>
  80. <div>
  81. Computes Manhattan length of this vector.<br />
  82. [link:http://en.wikipedia.org/wiki/Taxicab_geometry]
  83. </div>
  84. <h3>[method:Vector2 normalize]() [page:Vector2 this]</h3>
  85. <div>
  86. Normalizes this vector.
  87. </div>
  88. <h3>[method:Float distanceTo]( [page:Vector2 v] )</h3>
  89. <div>
  90. Computes distance of this vector to *v*.
  91. </div>
  92. <h3>[method:Float distanceToSquared]( [page:Vector2 v] )</h3>
  93. <div>
  94. Computes squared distance of this vector to *v*.
  95. </div>
  96. <h3>[method:Vector2 setLength]( [page:Float l] ) [page:Vector2 this]</h3>
  97. <div>
  98. Normalizes this vector and multiplies it by *l*.
  99. </div>
  100. <h3>[method:Boolean equals]( [page:Vector2 v] )</h3>
  101. <div>
  102. Checks for strict equality of this vector and *v*.
  103. </div>
  104. <h3>[method:Vector2 clone]()</h3>
  105. <div>
  106. Clones this vector.
  107. </div>
  108. <h3>[method:Vector2 clamp]([page:Vector2 min], [page:Vector2 max]) [page:Vector2 this]</h3>
  109. <div>
  110. min -- [page:Vector2] containing the min x and y values in the desired range <br />
  111. max -- [page:Vector2] containing the max x and y values in the desired range
  112. </div>
  113. <div>
  114. 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.
  115. </div>
  116. <h3>[method:Vector2 clampScalar]([page:Float min], [page:Float max]) [page:Vector2 this]</h3>
  117. <div>
  118. min -- [page:Float] the minimum value the components will be clamped to <br />
  119. max -- [page:Float] the maximum value the components will be clamped to
  120. </div>
  121. <div>
  122. 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.
  123. </div>
  124. <h3>[method:Vector2 floor]()</h3>
  125. <div>
  126. The components of the vector are rounded downwards (towards negative infinity) to an integer value.
  127. </div>
  128. <h3>[method:Vector2 ceil]()</h3>
  129. <div>
  130. The components of the vector are rounded upwards (towards positive infinity) to an integer value.
  131. </div>
  132. <h3>[method:Vector2 round]()</h3>
  133. <div>
  134. The components of the vector are rounded towards the nearest integer value.
  135. </div>
  136. <h3>[method:Vector2 roundToZero]()</h3>
  137. <div>
  138. The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.
  139. </div>
  140. <h3>[method:Vector2 lerp]([page:Vector2 v], [page:Float alpha]) [page:Vector2 this]</h3>
  141. <div>
  142. v -- [page:Vector2] <br />
  143. alpha -- [page:Float] between 0 and 1;
  144. </div>
  145. <div>
  146. Linear interpolation between this vector and v, where alpha is the percent along the line.
  147. </div>
  148. <h3>[method:Vector2 lerpVectors]([page:Vector2 v1], [page:Vector2 v2], [page:Float alpha]) [page:Vector2 this]</h3>
  149. <div>
  150. v1 -- [page:Vector2] <br />
  151. v2 -- [page:Vector2] <br />
  152. alpha -- [page:Float] between 0 and 1.
  153. </div>
  154. <div>
  155. Sets this vector to be the vector linearly interpolated between *v1* and *v2* with *alpha* factor.
  156. </div>
  157. <h3>[method:undefined setComponent]([page:Integer index], [page:Float value])</h3>
  158. <div>
  159. index -- 0 or 1 <br />
  160. value -- [page:Float]
  161. </div>
  162. <div>
  163. if index equals 0 method replaces this.x with value. <br />
  164. if index equals 1 method replaces this.y with value.
  165. </div>
  166. <h3>[method:Vector2 addScalar]([page:Float s]) [page:Vector2 this]</h3>
  167. <div>
  168. s -- [page:Float]
  169. </div>
  170. <div>
  171. Add the scalar value s to this vector's x and y values.
  172. </div>
  173. <h3>[method:Float getComponent]([page:Integer index])</h3>
  174. <div>
  175. index -- 0 or 1
  176. </div>
  177. <div>
  178. if index equals 0 returns the x value. <br />
  179. if index equals 1 returns the y value.
  180. </div>
  181. <h3>[method:Vector2 fromArray]([page:Array array]) [page:Vector2 this]</h3>
  182. <div>
  183. array -- [page:Array] of length 2
  184. </div>
  185. <div>
  186. Sets this vector's x value to be array[0] and y value to be array[1].
  187. </div>
  188. <h3>[method:Array toArray]( [page:Array array] )</h3>
  189. <div>
  190. array -- Optional array to store the vector.
  191. </div>
  192. <div>
  193. Returns an array [x, y].
  194. </div>
  195. <h3>[method:Vector2 min]([page:Vector2 v]) [page:Vector2 this]</h3>
  196. <div>
  197. v -- [page:Vector2]
  198. </div>
  199. <div>
  200. 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.
  201. </div>
  202. <h3>[method:Vector2 max]([page:Vector2 v]) [page:Vector2 this]</h3>
  203. <div>
  204. v -- [page:Vector2]
  205. </div>
  206. <div>
  207. 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.
  208. </div>
  209. <h3>[method:Vector2 setX]([page:Float x]) [page:Vector2 this]</h3>
  210. <div>
  211. x -- [page:Float]
  212. </div>
  213. <div>
  214. replace this vector's x value with x.
  215. </div>
  216. <h3>[method:Vector2 setY]([page:Float y]) [page:Vector2 this]</h3>
  217. <div>
  218. y -- [page:Float]
  219. </div>
  220. <div>
  221. replace this vector's y value with y.
  222. </div>
  223. <h2>Source</h2>
  224. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  225. </body>
  226. </html>