Vector2.html 7.3 KB

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