1
0

Vector2.html 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Vector2 - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <h1 translate="no">Vector2</h1>
  13. <section>
  14. <header>
  15. <div class="class-description"><p>Class representing a 2D vector. A 2D vector is an ordered pair of numbers
  16. (labeled x and y), which can be used to represent a number of things, such as:</p>
  17. <ul>
  18. <li>A point in 2D space (i.e. a position on a plane).</li>
  19. <li>A direction and length across a plane. In three.js the length will
  20. always be the Euclidean distance(straight-line distance) from <code>(0, 0)</code> to <code>(x, y)</code>
  21. and the direction is also measured from <code>(0, 0)</code> towards <code>(x, y)</code>.</li>
  22. <li>Any arbitrary ordered pair of numbers.</li>
  23. </ul>
  24. <p>There are other things a 2D vector can be used to represent, such as
  25. momentum vectors, complex numbers and so on, however these are the most
  26. common uses in three.js.</p>
  27. <p>Iterating through a vector instance will yield its components <code>(x, y)</code> in
  28. the corresponding order.</p></div>
  29. <h2>Code Example</h2>
  30. <div translate="no"><pre><code class="language-js">const a = new THREE.Vector2( 0, 1 );
  31. //no arguments; will be initialised to (0, 0)
  32. const b = new THREE.Vector2( );
  33. const d = a.distanceTo( b );
  34. </code></pre></div>
  35. </header>
  36. <article>
  37. <div class="container-overview">
  38. <h2>Constructor</h2>
  39. <h3 class="name name-method" id="Vector2" translate="no">new <a href="#Vector2">Vector2</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span> )</span> </h3>
  40. <div class="method">
  41. <div class="description">
  42. <p>Constructs a new 2D vector.</p>
  43. </div>
  44. <table class="params">
  45. <tbody>
  46. <tr>
  47. <td class="name">
  48. <strong>x</strong>
  49. </td>
  50. <td class="description last">
  51. <p>The x value of this vector.</p>
  52. <p>Default is <code>0</code>.</p>
  53. </td>
  54. </tr>
  55. <tr>
  56. <td class="name">
  57. <strong>y</strong>
  58. </td>
  59. <td class="description last">
  60. <p>The y value of this vector.</p>
  61. <p>Default is <code>0</code>.</p>
  62. </td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. </div>
  67. </div>
  68. <h2 class="subsection-title">Properties</h2>
  69. <div class="member">
  70. <h3 class="name" id="height" translate="no">.<a href="#height">height</a><span class="type-signature"> : number</span> </h3>
  71. <div class="description">
  72. <p>Alias for <a href="Vector2.html#y">Vector2#y</a>.</p>
  73. </div>
  74. </div>
  75. <div class="member">
  76. <h3 class="name" id="isVector2" translate="no">.<a href="#isVector2">isVector2</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  77. <div class="description">
  78. <p>This flag can be used for type testing.</p>
  79. <p>Default is <code>true</code>.</p>
  80. </div>
  81. </div>
  82. <div class="member">
  83. <h3 class="name" id="width" translate="no">.<a href="#width">width</a><span class="type-signature"> : number</span> </h3>
  84. <div class="description">
  85. <p>Alias for <a href="Vector2.html#x">Vector2#x</a>.</p>
  86. </div>
  87. </div>
  88. <div class="member">
  89. <h3 class="name" id="x" translate="no">.<a href="#x">x</a><span class="type-signature"> : number</span> </h3>
  90. <div class="description">
  91. <p>The x value of this vector.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="y" translate="no">.<a href="#y">y</a><span class="type-signature"> : number</span> </h3>
  96. <div class="description">
  97. <p>The y value of this vector.</p>
  98. </div>
  99. </div>
  100. <h2 class="subsection-title">Methods</h2>
  101. <h3 class="name name-method" id="add" translate="no">.<a href="#add">add</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  102. <div class="method">
  103. <div class="description">
  104. <p>Adds the given vector to this instance.</p>
  105. </div>
  106. <table class="params">
  107. <tbody>
  108. <tr>
  109. <td class="name">
  110. <strong>v</strong>
  111. </td>
  112. <td class="description last">
  113. <p>The vector to add.</p>
  114. </td>
  115. </tr>
  116. </tbody>
  117. </table>
  118. <dl class="details">
  119. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  120. </dl>
  121. </div>
  122. <h3 class="name name-method" id="addScalar" translate="no">.<a href="#addScalar">addScalar</a><span class="signature">( s : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  123. <div class="method">
  124. <div class="description">
  125. <p>Adds the given scalar value to all components of this instance.</p>
  126. </div>
  127. <table class="params">
  128. <tbody>
  129. <tr>
  130. <td class="name">
  131. <strong>s</strong>
  132. </td>
  133. <td class="description last">
  134. <p>The scalar to add.</p>
  135. </td>
  136. </tr>
  137. </tbody>
  138. </table>
  139. <dl class="details">
  140. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  141. </dl>
  142. </div>
  143. <h3 class="name name-method" id="addScaledVector" translate="no">.<a href="#addScaledVector">addScaledVector</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, s : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  144. <div class="method">
  145. <div class="description">
  146. <p>Adds the given vector scaled by the given factor to this instance.</p>
  147. </div>
  148. <table class="params">
  149. <tbody>
  150. <tr>
  151. <td class="name">
  152. <strong>v</strong>
  153. </td>
  154. <td class="description last">
  155. <p>The vector.</p>
  156. </td>
  157. </tr>
  158. <tr>
  159. <td class="name">
  160. <strong>s</strong>
  161. </td>
  162. <td class="description last">
  163. <p>The factor that scales <code>v</code>.</p>
  164. </td>
  165. </tr>
  166. </tbody>
  167. </table>
  168. <dl class="details">
  169. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  170. </dl>
  171. </div>
  172. <h3 class="name name-method" id="addVectors" translate="no">.<a href="#addVectors">addVectors</a><span class="signature">( a : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, b : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  173. <div class="method">
  174. <div class="description">
  175. <p>Adds the given vectors and stores the result in this instance.</p>
  176. </div>
  177. <table class="params">
  178. <tbody>
  179. <tr>
  180. <td class="name">
  181. <strong>a</strong>
  182. </td>
  183. <td class="description last">
  184. <p>The first vector.</p>
  185. </td>
  186. </tr>
  187. <tr>
  188. <td class="name">
  189. <strong>b</strong>
  190. </td>
  191. <td class="description last">
  192. <p>The second vector.</p>
  193. </td>
  194. </tr>
  195. </tbody>
  196. </table>
  197. <dl class="details">
  198. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  199. </dl>
  200. </div>
  201. <h3 class="name name-method" id="angle" translate="no">.<a href="#angle">angle</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  202. <div class="method">
  203. <div class="description">
  204. <p>Computes the angle in radians of this vector with respect to the positive x-axis.</p>
  205. </div>
  206. <dl class="details">
  207. <dt class="tag-returns"><strong>Returns:</strong> The angle in radians.</dt>
  208. </dl>
  209. </div>
  210. <h3 class="name name-method" id="angleTo" translate="no">.<a href="#angleTo">angleTo</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  211. <div class="method">
  212. <div class="description">
  213. <p>Returns the angle between the given vector and this instance in radians.</p>
  214. </div>
  215. <table class="params">
  216. <tbody>
  217. <tr>
  218. <td class="name">
  219. <strong>v</strong>
  220. </td>
  221. <td class="description last">
  222. <p>The vector to compute the angle with.</p>
  223. </td>
  224. </tr>
  225. </tbody>
  226. </table>
  227. <dl class="details">
  228. <dt class="tag-returns"><strong>Returns:</strong> The angle in radians.</dt>
  229. </dl>
  230. </div>
  231. <h3 class="name name-method" id="applyMatrix3" translate="no">.<a href="#applyMatrix3">applyMatrix3</a><span class="signature">( m : <span class="param-type"><a href="Matrix3.html">Matrix3</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  232. <div class="method">
  233. <div class="description">
  234. <p>Multiplies this vector (with an implicit 1 as the 3rd component) by
  235. the given 3x3 matrix.</p>
  236. </div>
  237. <table class="params">
  238. <tbody>
  239. <tr>
  240. <td class="name">
  241. <strong>m</strong>
  242. </td>
  243. <td class="description last">
  244. <p>The matrix to apply.</p>
  245. </td>
  246. </tr>
  247. </tbody>
  248. </table>
  249. <dl class="details">
  250. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  251. </dl>
  252. </div>
  253. <h3 class="name name-method" id="ceil" translate="no">.<a href="#ceil">ceil</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  254. <div class="method">
  255. <div class="description">
  256. <p>The components of this vector are rounded up to the nearest integer value.</p>
  257. </div>
  258. <dl class="details">
  259. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  260. </dl>
  261. </div>
  262. <h3 class="name name-method" id="clamp" translate="no">.<a href="#clamp">clamp</a><span class="signature">( min : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, max : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  263. <div class="method">
  264. <div class="description">
  265. <p>If this vector's x or y value is greater than the max vector's x or y
  266. value, it is replaced by the corresponding value.
  267. If this vector's x or y value is less than the min vector's x or y value,
  268. it is replaced by the corresponding value.</p>
  269. </div>
  270. <table class="params">
  271. <tbody>
  272. <tr>
  273. <td class="name">
  274. <strong>min</strong>
  275. </td>
  276. <td class="description last">
  277. <p>The minimum x and y values.</p>
  278. </td>
  279. </tr>
  280. <tr>
  281. <td class="name">
  282. <strong>max</strong>
  283. </td>
  284. <td class="description last">
  285. <p>The maximum x and y values in the desired range.</p>
  286. </td>
  287. </tr>
  288. </tbody>
  289. </table>
  290. <dl class="details">
  291. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  292. </dl>
  293. </div>
  294. <h3 class="name name-method" id="clampLength" translate="no">.<a href="#clampLength">clampLength</a><span class="signature">( min : <span class="param-type">number</span>, max : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  295. <div class="method">
  296. <div class="description">
  297. <p>If this vector's length is greater than the max value, it is replaced by
  298. the max value.
  299. If this vector's length is less than the min value, it is replaced by the
  300. min value.</p>
  301. </div>
  302. <table class="params">
  303. <tbody>
  304. <tr>
  305. <td class="name">
  306. <strong>min</strong>
  307. </td>
  308. <td class="description last">
  309. <p>The minimum value the vector length will be clamped to.</p>
  310. </td>
  311. </tr>
  312. <tr>
  313. <td class="name">
  314. <strong>max</strong>
  315. </td>
  316. <td class="description last">
  317. <p>The maximum value the vector length will be clamped to.</p>
  318. </td>
  319. </tr>
  320. </tbody>
  321. </table>
  322. <dl class="details">
  323. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  324. </dl>
  325. </div>
  326. <h3 class="name name-method" id="clampScalar" translate="no">.<a href="#clampScalar">clampScalar</a><span class="signature">( minVal : <span class="param-type">number</span>, maxVal : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  327. <div class="method">
  328. <div class="description">
  329. <p>If this vector's x or y values are greater than the max value, they are
  330. replaced by the max value.
  331. If this vector's x or y values are less than the min value, they are
  332. replaced by the min value.</p>
  333. </div>
  334. <table class="params">
  335. <tbody>
  336. <tr>
  337. <td class="name">
  338. <strong>minVal</strong>
  339. </td>
  340. <td class="description last">
  341. <p>The minimum value the components will be clamped to.</p>
  342. </td>
  343. </tr>
  344. <tr>
  345. <td class="name">
  346. <strong>maxVal</strong>
  347. </td>
  348. <td class="description last">
  349. <p>The maximum value the components will be clamped to.</p>
  350. </td>
  351. </tr>
  352. </tbody>
  353. </table>
  354. <dl class="details">
  355. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  356. </dl>
  357. </div>
  358. <h3 class="name name-method" id="clone" translate="no">.<a href="#clone">clone</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  359. <div class="method">
  360. <div class="description">
  361. <p>Returns a new vector with copied values from this instance.</p>
  362. </div>
  363. <dl class="details">
  364. <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
  365. </dl>
  366. </div>
  367. <h3 class="name name-method" id="copy" translate="no">.<a href="#copy">copy</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  368. <div class="method">
  369. <div class="description">
  370. <p>Copies the values of the given vector to this instance.</p>
  371. </div>
  372. <table class="params">
  373. <tbody>
  374. <tr>
  375. <td class="name">
  376. <strong>v</strong>
  377. </td>
  378. <td class="description last">
  379. <p>The vector to copy.</p>
  380. </td>
  381. </tr>
  382. </tbody>
  383. </table>
  384. <dl class="details">
  385. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  386. </dl>
  387. </div>
  388. <h3 class="name name-method" id="cross" translate="no">.<a href="#cross">cross</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  389. <div class="method">
  390. <div class="description">
  391. <p>Calculates the cross product of the given vector with this instance.</p>
  392. </div>
  393. <table class="params">
  394. <tbody>
  395. <tr>
  396. <td class="name">
  397. <strong>v</strong>
  398. </td>
  399. <td class="description last">
  400. <p>The vector to compute the cross product with.</p>
  401. </td>
  402. </tr>
  403. </tbody>
  404. </table>
  405. <dl class="details">
  406. <dt class="tag-returns"><strong>Returns:</strong> The result of the cross product.</dt>
  407. </dl>
  408. </div>
  409. <h3 class="name name-method" id="distanceTo" translate="no">.<a href="#distanceTo">distanceTo</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  410. <div class="method">
  411. <div class="description">
  412. <p>Computes the distance from the given vector to this instance.</p>
  413. </div>
  414. <table class="params">
  415. <tbody>
  416. <tr>
  417. <td class="name">
  418. <strong>v</strong>
  419. </td>
  420. <td class="description last">
  421. <p>The vector to compute the distance to.</p>
  422. </td>
  423. </tr>
  424. </tbody>
  425. </table>
  426. <dl class="details">
  427. <dt class="tag-returns"><strong>Returns:</strong> The distance.</dt>
  428. </dl>
  429. </div>
  430. <h3 class="name name-method" id="distanceToSquared" translate="no">.<a href="#distanceToSquared">distanceToSquared</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  431. <div class="method">
  432. <div class="description">
  433. <p>Computes the squared distance from the given vector to this instance.
  434. If you are just comparing the distance with another distance, you should compare
  435. the distance squared instead as it is slightly more efficient to calculate.</p>
  436. </div>
  437. <table class="params">
  438. <tbody>
  439. <tr>
  440. <td class="name">
  441. <strong>v</strong>
  442. </td>
  443. <td class="description last">
  444. <p>The vector to compute the squared distance to.</p>
  445. </td>
  446. </tr>
  447. </tbody>
  448. </table>
  449. <dl class="details">
  450. <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
  451. </dl>
  452. </div>
  453. <h3 class="name name-method" id="divide" translate="no">.<a href="#divide">divide</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  454. <div class="method">
  455. <div class="description">
  456. <p>Divides this instance by the given vector.</p>
  457. </div>
  458. <table class="params">
  459. <tbody>
  460. <tr>
  461. <td class="name">
  462. <strong>v</strong>
  463. </td>
  464. <td class="description last">
  465. <p>The vector to divide.</p>
  466. </td>
  467. </tr>
  468. </tbody>
  469. </table>
  470. <dl class="details">
  471. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  472. </dl>
  473. </div>
  474. <h3 class="name name-method" id="divideScalar" translate="no">.<a href="#divideScalar">divideScalar</a><span class="signature">( scalar : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  475. <div class="method">
  476. <div class="description">
  477. <p>Divides this vector by the given scalar.</p>
  478. </div>
  479. <table class="params">
  480. <tbody>
  481. <tr>
  482. <td class="name">
  483. <strong>scalar</strong>
  484. </td>
  485. <td class="description last">
  486. <p>The scalar to divide.</p>
  487. </td>
  488. </tr>
  489. </tbody>
  490. </table>
  491. <dl class="details">
  492. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  493. </dl>
  494. </div>
  495. <h3 class="name name-method" id="dot" translate="no">.<a href="#dot">dot</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  496. <div class="method">
  497. <div class="description">
  498. <p>Calculates the dot product of the given vector with this instance.</p>
  499. </div>
  500. <table class="params">
  501. <tbody>
  502. <tr>
  503. <td class="name">
  504. <strong>v</strong>
  505. </td>
  506. <td class="description last">
  507. <p>The vector to compute the dot product with.</p>
  508. </td>
  509. </tr>
  510. </tbody>
  511. </table>
  512. <dl class="details">
  513. <dt class="tag-returns"><strong>Returns:</strong> The result of the dot product.</dt>
  514. </dl>
  515. </div>
  516. <h3 class="name name-method" id="equals" translate="no">.<a href="#equals">equals</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : boolean</span> </h3>
  517. <div class="method">
  518. <div class="description">
  519. <p>Returns <code>true</code> if this vector is equal with the given one.</p>
  520. </div>
  521. <table class="params">
  522. <tbody>
  523. <tr>
  524. <td class="name">
  525. <strong>v</strong>
  526. </td>
  527. <td class="description last">
  528. <p>The vector to test for equality.</p>
  529. </td>
  530. </tr>
  531. </tbody>
  532. </table>
  533. <dl class="details">
  534. <dt class="tag-returns"><strong>Returns:</strong> Whether this vector is equal with the given one.</dt>
  535. </dl>
  536. </div>
  537. <h3 class="name name-method" id="floor" translate="no">.<a href="#floor">floor</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  538. <div class="method">
  539. <div class="description">
  540. <p>The components of this vector are rounded down to the nearest integer value.</p>
  541. </div>
  542. <dl class="details">
  543. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  544. </dl>
  545. </div>
  546. <h3 class="name name-method" id="fromArray" translate="no">.<a href="#fromArray">fromArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  547. <div class="method">
  548. <div class="description">
  549. <p>Sets this vector's x value to be <code>array[ offset ]</code> and y
  550. value to be <code>array[ offset + 1 ]</code>.</p>
  551. </div>
  552. <table class="params">
  553. <tbody>
  554. <tr>
  555. <td class="name">
  556. <strong>array</strong>
  557. </td>
  558. <td class="description last">
  559. <p>An array holding the vector component values.</p>
  560. </td>
  561. </tr>
  562. <tr>
  563. <td class="name">
  564. <strong>offset</strong>
  565. </td>
  566. <td class="description last">
  567. <p>The offset into the array.</p>
  568. <p>Default is <code>0</code>.</p>
  569. </td>
  570. </tr>
  571. </tbody>
  572. </table>
  573. <dl class="details">
  574. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  575. </dl>
  576. </div>
  577. <h3 class="name name-method" id="fromBufferAttribute" translate="no">.<a href="#fromBufferAttribute">fromBufferAttribute</a><span class="signature">( attribute : <span class="param-type"><a href="BufferAttribute.html">BufferAttribute</a></span>, index : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  578. <div class="method">
  579. <div class="description">
  580. <p>Sets the components of this vector from the given buffer attribute.</p>
  581. </div>
  582. <table class="params">
  583. <tbody>
  584. <tr>
  585. <td class="name">
  586. <strong>attribute</strong>
  587. </td>
  588. <td class="description last">
  589. <p>The buffer attribute holding vector data.</p>
  590. </td>
  591. </tr>
  592. <tr>
  593. <td class="name">
  594. <strong>index</strong>
  595. </td>
  596. <td class="description last">
  597. <p>The index into the attribute.</p>
  598. </td>
  599. </tr>
  600. </tbody>
  601. </table>
  602. <dl class="details">
  603. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  604. </dl>
  605. </div>
  606. <h3 class="name name-method" id="getComponent" translate="no">.<a href="#getComponent">getComponent</a><span class="signature">( index : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
  607. <div class="method">
  608. <div class="description">
  609. <p>Returns the value of the vector component which matches the given index.</p>
  610. </div>
  611. <table class="params">
  612. <tbody>
  613. <tr>
  614. <td class="name">
  615. <strong>index</strong>
  616. </td>
  617. <td class="description last">
  618. <p>The component index. <code>0</code> equals to x, <code>1</code> equals to y.</p>
  619. </td>
  620. </tr>
  621. </tbody>
  622. </table>
  623. <dl class="details">
  624. <dt class="tag-returns"><strong>Returns:</strong> A vector component value.</dt>
  625. </dl>
  626. </div>
  627. <h3 class="name name-method" id="length" translate="no">.<a href="#length">length</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  628. <div class="method">
  629. <div class="description">
  630. <p>Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).</p>
  631. </div>
  632. <dl class="details">
  633. <dt class="tag-returns"><strong>Returns:</strong> The length of this vector.</dt>
  634. </dl>
  635. </div>
  636. <h3 class="name name-method" id="lengthSq" translate="no">.<a href="#lengthSq">lengthSq</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  637. <div class="method">
  638. <div class="description">
  639. <p>Computes the square of the Euclidean length (straight-line length) from
  640. (0, 0) to (x, y). If you are comparing the lengths of vectors, you should
  641. compare the length squared instead as it is slightly more efficient to calculate.</p>
  642. </div>
  643. <dl class="details">
  644. <dt class="tag-returns"><strong>Returns:</strong> The square length of this vector.</dt>
  645. </dl>
  646. </div>
  647. <h3 class="name name-method" id="lerp" translate="no">.<a href="#lerp">lerp</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, alpha : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  648. <div class="method">
  649. <div class="description">
  650. <p>Linearly interpolates between the given vector and this instance, where
  651. alpha is the percent distance along the line - alpha = 0 will be this
  652. vector, and alpha = 1 will be the given one.</p>
  653. </div>
  654. <table class="params">
  655. <tbody>
  656. <tr>
  657. <td class="name">
  658. <strong>v</strong>
  659. </td>
  660. <td class="description last">
  661. <p>The vector to interpolate towards.</p>
  662. </td>
  663. </tr>
  664. <tr>
  665. <td class="name">
  666. <strong>alpha</strong>
  667. </td>
  668. <td class="description last">
  669. <p>The interpolation factor, typically in the closed interval <code>[0, 1]</code>.</p>
  670. </td>
  671. </tr>
  672. </tbody>
  673. </table>
  674. <dl class="details">
  675. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  676. </dl>
  677. </div>
  678. <h3 class="name name-method" id="lerpVectors" translate="no">.<a href="#lerpVectors">lerpVectors</a><span class="signature">( v1 : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, v2 : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, alpha : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  679. <div class="method">
  680. <div class="description">
  681. <p>Linearly interpolates between the given vectors, where alpha is the percent
  682. distance along the line - alpha = 0 will be first vector, and alpha = 1 will
  683. be the second one. The result is stored in this instance.</p>
  684. </div>
  685. <table class="params">
  686. <tbody>
  687. <tr>
  688. <td class="name">
  689. <strong>v1</strong>
  690. </td>
  691. <td class="description last">
  692. <p>The first vector.</p>
  693. </td>
  694. </tr>
  695. <tr>
  696. <td class="name">
  697. <strong>v2</strong>
  698. </td>
  699. <td class="description last">
  700. <p>The second vector.</p>
  701. </td>
  702. </tr>
  703. <tr>
  704. <td class="name">
  705. <strong>alpha</strong>
  706. </td>
  707. <td class="description last">
  708. <p>The interpolation factor, typically in the closed interval <code>[0, 1]</code>.</p>
  709. </td>
  710. </tr>
  711. </tbody>
  712. </table>
  713. <dl class="details">
  714. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  715. </dl>
  716. </div>
  717. <h3 class="name name-method" id="manhattanDistanceTo" translate="no">.<a href="#manhattanDistanceTo">manhattanDistanceTo</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : number</span> </h3>
  718. <div class="method">
  719. <div class="description">
  720. <p>Computes the Manhattan distance from the given vector to this instance.</p>
  721. </div>
  722. <table class="params">
  723. <tbody>
  724. <tr>
  725. <td class="name">
  726. <strong>v</strong>
  727. </td>
  728. <td class="description last">
  729. <p>The vector to compute the Manhattan distance to.</p>
  730. </td>
  731. </tr>
  732. </tbody>
  733. </table>
  734. <dl class="details">
  735. <dt class="tag-returns"><strong>Returns:</strong> The Manhattan distance.</dt>
  736. </dl>
  737. </div>
  738. <h3 class="name name-method" id="manhattanLength" translate="no">.<a href="#manhattanLength">manhattanLength</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  739. <div class="method">
  740. <div class="description">
  741. <p>Computes the Manhattan length of this vector.</p>
  742. </div>
  743. <dl class="details">
  744. <dt class="tag-returns"><strong>Returns:</strong> The length of this vector.</dt>
  745. </dl>
  746. </div>
  747. <h3 class="name name-method" id="max" translate="no">.<a href="#max">max</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  748. <div class="method">
  749. <div class="description">
  750. <p>If this vector's x or y value is less than the given vector's x or y
  751. value, replace that value with the corresponding max value.</p>
  752. </div>
  753. <table class="params">
  754. <tbody>
  755. <tr>
  756. <td class="name">
  757. <strong>v</strong>
  758. </td>
  759. <td class="description last">
  760. <p>The vector.</p>
  761. </td>
  762. </tr>
  763. </tbody>
  764. </table>
  765. <dl class="details">
  766. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  767. </dl>
  768. </div>
  769. <h3 class="name name-method" id="min" translate="no">.<a href="#min">min</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  770. <div class="method">
  771. <div class="description">
  772. <p>If this vector's x or y value is greater than the given vector's x or y
  773. value, replace that value with the corresponding min value.</p>
  774. </div>
  775. <table class="params">
  776. <tbody>
  777. <tr>
  778. <td class="name">
  779. <strong>v</strong>
  780. </td>
  781. <td class="description last">
  782. <p>The vector.</p>
  783. </td>
  784. </tr>
  785. </tbody>
  786. </table>
  787. <dl class="details">
  788. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  789. </dl>
  790. </div>
  791. <h3 class="name name-method" id="multiply" translate="no">.<a href="#multiply">multiply</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  792. <div class="method">
  793. <div class="description">
  794. <p>Multiplies the given vector with this instance.</p>
  795. </div>
  796. <table class="params">
  797. <tbody>
  798. <tr>
  799. <td class="name">
  800. <strong>v</strong>
  801. </td>
  802. <td class="description last">
  803. <p>The vector to multiply.</p>
  804. </td>
  805. </tr>
  806. </tbody>
  807. </table>
  808. <dl class="details">
  809. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  810. </dl>
  811. </div>
  812. <h3 class="name name-method" id="multiplyScalar" translate="no">.<a href="#multiplyScalar">multiplyScalar</a><span class="signature">( scalar : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  813. <div class="method">
  814. <div class="description">
  815. <p>Multiplies the given scalar value with all components of this instance.</p>
  816. </div>
  817. <table class="params">
  818. <tbody>
  819. <tr>
  820. <td class="name">
  821. <strong>scalar</strong>
  822. </td>
  823. <td class="description last">
  824. <p>The scalar to multiply.</p>
  825. </td>
  826. </tr>
  827. </tbody>
  828. </table>
  829. <dl class="details">
  830. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  831. </dl>
  832. </div>
  833. <h3 class="name name-method" id="negate" translate="no">.<a href="#negate">negate</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  834. <div class="method">
  835. <div class="description">
  836. <p>Inverts this vector - i.e. sets x = -x and y = -y.</p>
  837. </div>
  838. <dl class="details">
  839. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  840. </dl>
  841. </div>
  842. <h3 class="name name-method" id="normalize" translate="no">.<a href="#normalize">normalize</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  843. <div class="method">
  844. <div class="description">
  845. <p>Converts this vector to a unit vector - that is, sets it equal to a vector
  846. with the same direction as this one, but with a vector length of <code>1</code>.</p>
  847. </div>
  848. <dl class="details">
  849. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  850. </dl>
  851. </div>
  852. <h3 class="name name-method" id="random" translate="no">.<a href="#random">random</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  853. <div class="method">
  854. <div class="description">
  855. <p>Sets each component of this vector to a pseudo-random value between <code>0</code> and
  856. <code>1</code>, excluding <code>1</code>.</p>
  857. </div>
  858. <dl class="details">
  859. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  860. </dl>
  861. </div>
  862. <h3 class="name name-method" id="rotateAround" translate="no">.<a href="#rotateAround">rotateAround</a><span class="signature">( center : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, angle : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  863. <div class="method">
  864. <div class="description">
  865. <p>Rotates this vector around the given center by the given angle.</p>
  866. </div>
  867. <table class="params">
  868. <tbody>
  869. <tr>
  870. <td class="name">
  871. <strong>center</strong>
  872. </td>
  873. <td class="description last">
  874. <p>The point around which to rotate.</p>
  875. </td>
  876. </tr>
  877. <tr>
  878. <td class="name">
  879. <strong>angle</strong>
  880. </td>
  881. <td class="description last">
  882. <p>The angle to rotate, in radians.</p>
  883. </td>
  884. </tr>
  885. </tbody>
  886. </table>
  887. <dl class="details">
  888. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  889. </dl>
  890. </div>
  891. <h3 class="name name-method" id="round" translate="no">.<a href="#round">round</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  892. <div class="method">
  893. <div class="description">
  894. <p>The components of this vector are rounded to the nearest integer value</p>
  895. </div>
  896. <dl class="details">
  897. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  898. </dl>
  899. </div>
  900. <h3 class="name name-method" id="roundToZero" translate="no">.<a href="#roundToZero">roundToZero</a><span class="signature">()</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  901. <div class="method">
  902. <div class="description">
  903. <p>The components of this vector are rounded towards zero (up if negative,
  904. down if positive) to an integer value.</p>
  905. </div>
  906. <dl class="details">
  907. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  908. </dl>
  909. </div>
  910. <h3 class="name name-method" id="set" translate="no">.<a href="#set">set</a><span class="signature">( x : <span class="param-type">number</span>, y : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  911. <div class="method">
  912. <div class="description">
  913. <p>Sets the vector components.</p>
  914. </div>
  915. <table class="params">
  916. <tbody>
  917. <tr>
  918. <td class="name">
  919. <strong>x</strong>
  920. </td>
  921. <td class="description last">
  922. <p>The value of the x component.</p>
  923. </td>
  924. </tr>
  925. <tr>
  926. <td class="name">
  927. <strong>y</strong>
  928. </td>
  929. <td class="description last">
  930. <p>The value of the y component.</p>
  931. </td>
  932. </tr>
  933. </tbody>
  934. </table>
  935. <dl class="details">
  936. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  937. </dl>
  938. </div>
  939. <h3 class="name name-method" id="setComponent" translate="no">.<a href="#setComponent">setComponent</a><span class="signature">( index : <span class="param-type">number</span>, value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  940. <div class="method">
  941. <div class="description">
  942. <p>Allows to set a vector component with an index.</p>
  943. </div>
  944. <table class="params">
  945. <tbody>
  946. <tr>
  947. <td class="name">
  948. <strong>index</strong>
  949. </td>
  950. <td class="description last">
  951. <p>The component index. <code>0</code> equals to x, <code>1</code> equals to y.</p>
  952. </td>
  953. </tr>
  954. <tr>
  955. <td class="name">
  956. <strong>value</strong>
  957. </td>
  958. <td class="description last">
  959. <p>The value to set.</p>
  960. </td>
  961. </tr>
  962. </tbody>
  963. </table>
  964. <dl class="details">
  965. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  966. </dl>
  967. </div>
  968. <h3 class="name name-method" id="setLength" translate="no">.<a href="#setLength">setLength</a><span class="signature">( length : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  969. <div class="method">
  970. <div class="description">
  971. <p>Sets this vector to a vector with the same direction as this one, but
  972. with the specified length.</p>
  973. </div>
  974. <table class="params">
  975. <tbody>
  976. <tr>
  977. <td class="name">
  978. <strong>length</strong>
  979. </td>
  980. <td class="description last">
  981. <p>The new length of this vector.</p>
  982. </td>
  983. </tr>
  984. </tbody>
  985. </table>
  986. <dl class="details">
  987. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  988. </dl>
  989. </div>
  990. <h3 class="name name-method" id="setScalar" translate="no">.<a href="#setScalar">setScalar</a><span class="signature">( scalar : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  991. <div class="method">
  992. <div class="description">
  993. <p>Sets the vector components to the same value.</p>
  994. </div>
  995. <table class="params">
  996. <tbody>
  997. <tr>
  998. <td class="name">
  999. <strong>scalar</strong>
  1000. </td>
  1001. <td class="description last">
  1002. <p>The value to set for all vector components.</p>
  1003. </td>
  1004. </tr>
  1005. </tbody>
  1006. </table>
  1007. <dl class="details">
  1008. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1009. </dl>
  1010. </div>
  1011. <h3 class="name name-method" id="setX" translate="no">.<a href="#setX">setX</a><span class="signature">( x : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  1012. <div class="method">
  1013. <div class="description">
  1014. <p>Sets the vector's x component to the given value</p>
  1015. </div>
  1016. <table class="params">
  1017. <tbody>
  1018. <tr>
  1019. <td class="name">
  1020. <strong>x</strong>
  1021. </td>
  1022. <td class="description last">
  1023. <p>The value to set.</p>
  1024. </td>
  1025. </tr>
  1026. </tbody>
  1027. </table>
  1028. <dl class="details">
  1029. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1030. </dl>
  1031. </div>
  1032. <h3 class="name name-method" id="setY" translate="no">.<a href="#setY">setY</a><span class="signature">( y : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  1033. <div class="method">
  1034. <div class="description">
  1035. <p>Sets the vector's y component to the given value</p>
  1036. </div>
  1037. <table class="params">
  1038. <tbody>
  1039. <tr>
  1040. <td class="name">
  1041. <strong>y</strong>
  1042. </td>
  1043. <td class="description last">
  1044. <p>The value to set.</p>
  1045. </td>
  1046. </tr>
  1047. </tbody>
  1048. </table>
  1049. <dl class="details">
  1050. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1051. </dl>
  1052. </div>
  1053. <h3 class="name name-method" id="sub" translate="no">.<a href="#sub">sub</a><span class="signature">( v : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  1054. <div class="method">
  1055. <div class="description">
  1056. <p>Subtracts the given vector from this instance.</p>
  1057. </div>
  1058. <table class="params">
  1059. <tbody>
  1060. <tr>
  1061. <td class="name">
  1062. <strong>v</strong>
  1063. </td>
  1064. <td class="description last">
  1065. <p>The vector to subtract.</p>
  1066. </td>
  1067. </tr>
  1068. </tbody>
  1069. </table>
  1070. <dl class="details">
  1071. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1072. </dl>
  1073. </div>
  1074. <h3 class="name name-method" id="subScalar" translate="no">.<a href="#subScalar">subScalar</a><span class="signature">( s : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  1075. <div class="method">
  1076. <div class="description">
  1077. <p>Subtracts the given scalar value from all components of this instance.</p>
  1078. </div>
  1079. <table class="params">
  1080. <tbody>
  1081. <tr>
  1082. <td class="name">
  1083. <strong>s</strong>
  1084. </td>
  1085. <td class="description last">
  1086. <p>The scalar to subtract.</p>
  1087. </td>
  1088. </tr>
  1089. </tbody>
  1090. </table>
  1091. <dl class="details">
  1092. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1093. </dl>
  1094. </div>
  1095. <h3 class="name name-method" id="subVectors" translate="no">.<a href="#subVectors">subVectors</a><span class="signature">( a : <span class="param-type"><a href="Vector2.html">Vector2</a></span>, b : <span class="param-type"><a href="Vector2.html">Vector2</a></span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
  1096. <div class="method">
  1097. <div class="description">
  1098. <p>Subtracts the given vectors and stores the result in this instance.</p>
  1099. </div>
  1100. <table class="params">
  1101. <tbody>
  1102. <tr>
  1103. <td class="name">
  1104. <strong>a</strong>
  1105. </td>
  1106. <td class="description last">
  1107. <p>The first vector.</p>
  1108. </td>
  1109. </tr>
  1110. <tr>
  1111. <td class="name">
  1112. <strong>b</strong>
  1113. </td>
  1114. <td class="description last">
  1115. <p>The second vector.</p>
  1116. </td>
  1117. </tr>
  1118. </tbody>
  1119. </table>
  1120. <dl class="details">
  1121. <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
  1122. </dl>
  1123. </div>
  1124. <h3 class="name name-method" id="toArray" translate="no">.<a href="#toArray">toArray</a><span class="signature">( array : <span class="param-type">Array.&lt;number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.&lt;number></span> </h3>
  1125. <div class="method">
  1126. <div class="description">
  1127. <p>Writes the components of this vector to the given array. If no array is provided,
  1128. the method returns a new instance.</p>
  1129. </div>
  1130. <table class="params">
  1131. <tbody>
  1132. <tr>
  1133. <td class="name">
  1134. <strong>array</strong>
  1135. </td>
  1136. <td class="description last">
  1137. <p>The target array holding the vector components.</p>
  1138. <p>Default is <code>[]</code>.</p>
  1139. </td>
  1140. </tr>
  1141. <tr>
  1142. <td class="name">
  1143. <strong>offset</strong>
  1144. </td>
  1145. <td class="description last">
  1146. <p>Index of the first element in the array.</p>
  1147. <p>Default is <code>0</code>.</p>
  1148. </td>
  1149. </tr>
  1150. </tbody>
  1151. </table>
  1152. <dl class="details">
  1153. <dt class="tag-returns"><strong>Returns:</strong> The vector components.</dt>
  1154. </dl>
  1155. </div>
  1156. <h2 class="subsection-title">Source</h2>
  1157. <p>
  1158. <a href="https://github.com/mrdoob/three.js/blob/master/src/math/Vector2.js" translate="no" target="_blank" rel="noopener">src/math/Vector2.js</a>
  1159. </p>
  1160. </article>
  1161. </section>
  1162. <script src="../scripts/linenumber.js"></script>
  1163. <script src="../scripts/page.js"></script>
  1164. </body>
  1165. </html>
粤ICP备19079148号