Vector2.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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>.lerp([page:Vector2 v], [page:Float alpha]) [page:Vector2 this]</h3>
  112. <div>
  113. v -- [page:Vector2] <br />
  114. alpha -- [page:Float] between 0 and 1;
  115. </div>
  116. <div>
  117. Linear interpolation between this vector and v, where alpha is the percent along the line.
  118. </div>
  119. <h3>.setComponent([page:Integer index], [page:Float value]) [page:undefined]</h3>
  120. <div>
  121. index -- 0 or 1 <br />
  122. value -- [page:Float]
  123. </div>
  124. <div>
  125. if index equals 0 method replaces this.x with value. <br />
  126. if index equals 1 method replaces this.y with value.
  127. </div>
  128. <h3>.addScalar([page:Float s]) [page:Vector2 this]</h3>
  129. <div>
  130. s -- [page:Float]
  131. </div>
  132. <div>
  133. Add the scalar value s to this vector's x and y values.
  134. </div>
  135. <h3>.getComponent([page:Integer index]) [page:Float]</h3>
  136. <div>
  137. index -- 0 or 1
  138. </div>
  139. <div>
  140. if index equals 0 returns the x value. <br />
  141. if index equals 1 returns the y value.
  142. </div>
  143. <h3>.fromArray([page:Array array]) [page:Vector2 this]</h3>
  144. <div>
  145. array -- [page:Array] of length 2
  146. </div>
  147. <div>
  148. Sets this vector's x value to be array[0] and y value to be array[1].
  149. </div>
  150. <h3>.toArray() [page:Array]</h3>
  151. <div>
  152. Returns an array [x, y].
  153. </div>
  154. <h3>.min([page:Vector2 v]) [page:Vector2 this]</h3>
  155. <div>
  156. v -- [page:Vector2]
  157. </div>
  158. <div>
  159. 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.
  160. </div>
  161. <h3>.max([page:Vector2 v]) [page:Vector2 this]</h3>
  162. <div>
  163. v -- [page:Vector2]
  164. </div>
  165. <div>
  166. 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.
  167. </div>
  168. <h3>.setX([page:Float x]) [page:Vector2 this]</h3>
  169. <div>
  170. x -- [page:Float]
  171. </div>
  172. <div>
  173. replace this vector's x value with x.
  174. </div>
  175. <h3>.setY([page:Float y]) [page:Vector2 this]</h3>
  176. <div>
  177. y -- [page:Float]
  178. </div>
  179. <div>
  180. replace this vector's y value with y.
  181. </div>
  182. <h2>Source</h2>
  183. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  184. </body>
  185. </html>