| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Vector2 - Three.js Docs</title>
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <script src="../scripts/highlight.min.js"></script>
- <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
- <link type="text/css" rel="stylesheet" href="../styles/page.css">
- </head>
- <body>
- <h1 translate="no">Vector2</h1>
- <section>
- <header>
- <div class="class-description"><p>Class representing a 2D vector. A 2D vector is an ordered pair of numbers
- (labeled x and y), which can be used to represent a number of things, such as:</p>
- <ul>
- <li>A point in 2D space (i.e. a position on a plane).</li>
- <li>A direction and length across a plane. In three.js the length will
- always be the Euclidean distance(straight-line distance) from <code>(0, 0)</code> to <code>(x, y)</code>
- and the direction is also measured from <code>(0, 0)</code> towards <code>(x, y)</code>.</li>
- <li>Any arbitrary ordered pair of numbers.</li>
- </ul>
- <p>There are other things a 2D vector can be used to represent, such as
- momentum vectors, complex numbers and so on, however these are the most
- common uses in three.js.</p>
- <p>Iterating through a vector instance will yield its components <code>(x, y)</code> in
- the corresponding order.</p></div>
- <h2>Code Example</h2>
- <div translate="no"><pre><code class="language-js">const a = new THREE.Vector2( 0, 1 );
- //no arguments; will be initialised to (0, 0)
- const b = new THREE.Vector2( );
- const d = a.distanceTo( b );
- </code></pre></div>
- </header>
- <article>
- <div class="container-overview">
- <h2>Constructor</h2>
- <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>
- <div class="method">
- <div class="description">
- <p>Constructs a new 2D vector.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>x</strong>
- </td>
- <td class="description last">
- <p>The x value of this vector.</p>
- <p>Default is <code>0</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>y</strong>
- </td>
- <td class="description last">
- <p>The y value of this vector.</p>
- <p>Default is <code>0</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <h2 class="subsection-title">Properties</h2>
- <div class="member">
- <h3 class="name" id="height" translate="no">.<a href="#height">height</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Alias for <a href="Vector2.html#y">Vector2#y</a>.</p>
- </div>
- </div>
- <div class="member">
- <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>
- <div class="description">
- <p>This flag can be used for type testing.</p>
- <p>Default is <code>true</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="width" translate="no">.<a href="#width">width</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Alias for <a href="Vector2.html#x">Vector2#x</a>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="x" translate="no">.<a href="#x">x</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The x value of this vector.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="y" translate="no">.<a href="#y">y</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>The y value of this vector.</p>
- </div>
- </div>
- <h2 class="subsection-title">Methods</h2>
- <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>
- <div class="method">
- <div class="description">
- <p>Adds the given vector to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to add.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Adds the given scalar value to all components of this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>s</strong>
- </td>
- <td class="description last">
- <p>The scalar to add.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Adds the given vector scaled by the given factor to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>s</strong>
- </td>
- <td class="description last">
- <p>The factor that scales <code>v</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Adds the given vectors and stores the result in this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>a</strong>
- </td>
- <td class="description last">
- <p>The first vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>b</strong>
- </td>
- <td class="description last">
- <p>The second vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the angle in radians of this vector with respect to the positive x-axis.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The angle in radians.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns the angle between the given vector and this instance in radians.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the angle with.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The angle in radians.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Multiplies this vector (with an implicit 1 as the 3rd component) by
- the given 3x3 matrix.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>m</strong>
- </td>
- <td class="description last">
- <p>The matrix to apply.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>The components of this vector are rounded up to the nearest integer value.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>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.
- 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.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>min</strong>
- </td>
- <td class="description last">
- <p>The minimum x and y values.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>max</strong>
- </td>
- <td class="description last">
- <p>The maximum x and y values in the desired range.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>If this vector's length is greater than the max value, it is replaced by
- the max value.
- If this vector's length is less than the min value, it is replaced by the
- min value.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>min</strong>
- </td>
- <td class="description last">
- <p>The minimum value the vector length will be clamped to.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>max</strong>
- </td>
- <td class="description last">
- <p>The maximum value the vector length will be clamped to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>If this vector's x or y values are greater than the max value, they are
- replaced by the max value.
- If this vector's x or y values are less than the min value, they are
- replaced by the min value.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>minVal</strong>
- </td>
- <td class="description last">
- <p>The minimum value the components will be clamped to.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>maxVal</strong>
- </td>
- <td class="description last">
- <p>The maximum value the components will be clamped to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns a new vector with copied values from this instance.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A clone of this instance.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Copies the values of the given vector to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to copy.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Calculates the cross product of the given vector with this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the cross product with.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The result of the cross product.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the distance from the given vector to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The distance.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the squared distance from the given vector to this instance.
- If you are just comparing the distance with another distance, you should compare
- the distance squared instead as it is slightly more efficient to calculate.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the squared distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The squared distance.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Divides this instance by the given vector.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to divide.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Divides this vector by the given scalar.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>scalar</strong>
- </td>
- <td class="description last">
- <p>The scalar to divide.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Calculates the dot product of the given vector with this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the dot product with.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The result of the dot product.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns <code>true</code> if this vector is equal with the given one.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to test for equality.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> Whether this vector is equal with the given one.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>The components of this vector are rounded down to the nearest integer value.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="fromArray" translate="no">.<a href="#fromArray">fromArray</a><span class="signature">( array : <span class="param-type">Array.<number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Vector2.html">Vector2</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Sets this vector's x value to be <code>array[ offset ]</code> and y
- value to be <code>array[ offset + 1 ]</code>.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>array</strong>
- </td>
- <td class="description last">
- <p>An array holding the vector component values.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>offset</strong>
- </td>
- <td class="description last">
- <p>The offset into the array.</p>
- <p>Default is <code>0</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets the components of this vector from the given buffer attribute.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>attribute</strong>
- </td>
- <td class="description last">
- <p>The buffer attribute holding vector data.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>index</strong>
- </td>
- <td class="description last">
- <p>The index into the attribute.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Returns the value of the vector component which matches the given index.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>index</strong>
- </td>
- <td class="description last">
- <p>The component index. <code>0</code> equals to x, <code>1</code> equals to y.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A vector component value.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the Euclidean length (straight-line length) from (0, 0) to (x, y).</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The length of this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the square of the Euclidean length (straight-line length) from
- (0, 0) to (x, y). If you are comparing the lengths of vectors, you should
- compare the length squared instead as it is slightly more efficient to calculate.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The square length of this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Linearly interpolates between the given vector and this instance, where
- alpha is the percent distance along the line - alpha = 0 will be this
- vector, and alpha = 1 will be the given one.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to interpolate towards.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>alpha</strong>
- </td>
- <td class="description last">
- <p>The interpolation factor, typically in the closed interval <code>[0, 1]</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Linearly interpolates between the given vectors, where alpha is the percent
- distance along the line - alpha = 0 will be first vector, and alpha = 1 will
- be the second one. The result is stored in this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v1</strong>
- </td>
- <td class="description last">
- <p>The first vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>v2</strong>
- </td>
- <td class="description last">
- <p>The second vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>alpha</strong>
- </td>
- <td class="description last">
- <p>The interpolation factor, typically in the closed interval <code>[0, 1]</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the Manhattan distance from the given vector to this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to compute the Manhattan distance to.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The Manhattan distance.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Computes the Manhattan length of this vector.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The length of this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>If this vector's x or y value is less than the given vector's x or y
- value, replace that value with the corresponding max value.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>If this vector's x or y value is greater than the given vector's x or y
- value, replace that value with the corresponding min value.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Multiplies the given vector with this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to multiply.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Multiplies the given scalar value with all components of this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>scalar</strong>
- </td>
- <td class="description last">
- <p>The scalar to multiply.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Inverts this vector - i.e. sets x = -x and y = -y.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Converts this vector to a unit vector - that is, sets it equal to a vector
- with the same direction as this one, but with a vector length of <code>1</code>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets each component of this vector to a pseudo-random value between <code>0</code> and
- <code>1</code>, excluding <code>1</code>.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Rotates this vector around the given center by the given angle.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>center</strong>
- </td>
- <td class="description last">
- <p>The point around which to rotate.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>angle</strong>
- </td>
- <td class="description last">
- <p>The angle to rotate, in radians.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>The components of this vector are rounded to the nearest integer value</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>The components of this vector are rounded towards zero (up if negative,
- down if positive) to an integer value.</p>
- </div>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets the vector components.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>x</strong>
- </td>
- <td class="description last">
- <p>The value of the x component.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>y</strong>
- </td>
- <td class="description last">
- <p>The value of the y component.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Allows to set a vector component with an index.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>index</strong>
- </td>
- <td class="description last">
- <p>The component index. <code>0</code> equals to x, <code>1</code> equals to y.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>value</strong>
- </td>
- <td class="description last">
- <p>The value to set.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets this vector to a vector with the same direction as this one, but
- with the specified length.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>length</strong>
- </td>
- <td class="description last">
- <p>The new length of this vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets the vector components to the same value.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>scalar</strong>
- </td>
- <td class="description last">
- <p>The value to set for all vector components.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets the vector's x component to the given value</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>x</strong>
- </td>
- <td class="description last">
- <p>The value to set.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Sets the vector's y component to the given value</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>y</strong>
- </td>
- <td class="description last">
- <p>The value to set.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Subtracts the given vector from this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>v</strong>
- </td>
- <td class="description last">
- <p>The vector to subtract.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Subtracts the given scalar value from all components of this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>s</strong>
- </td>
- <td class="description last">
- <p>The scalar to subtract.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <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>
- <div class="method">
- <div class="description">
- <p>Subtracts the given vectors and stores the result in this instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>a</strong>
- </td>
- <td class="description last">
- <p>The first vector.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>b</strong>
- </td>
- <td class="description last">
- <p>The second vector.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> A reference to this vector.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id="toArray" translate="no">.<a href="#toArray">toArray</a><span class="signature">( array : <span class="param-type">Array.<number></span>, offset : <span class="param-type">number</span> )</span><span class="type-signature"> : Array.<number></span> </h3>
- <div class="method">
- <div class="description">
- <p>Writes the components of this vector to the given array. If no array is provided,
- the method returns a new instance.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name">
- <strong>array</strong>
- </td>
- <td class="description last">
- <p>The target array holding the vector components.</p>
- <p>Default is <code>[]</code>.</p>
- </td>
- </tr>
- <tr>
- <td class="name">
- <strong>offset</strong>
- </td>
- <td class="description last">
- <p>Index of the first element in the array.</p>
- <p>Default is <code>0</code>.</p>
- </td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The vector components.</dt>
- </dl>
- </div>
- <h2 class="subsection-title">Source</h2>
- <p>
- <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>
- </p>
- </article>
- </section>
- <script src="../scripts/linenumber.js"></script>
- <script src="../scripts/page.js"></script>
- </body>
- </html>
|