[name]

2D vector.

Example

var a = new THREE.Vector2( 0, 1 ); var b = new THREE.Vector2( 1, 0 ); var d = a.distanceTo( b );

Constructor

[name]( [page:Float x], [page:Float y] )

x -- [page:Float] representing the x value of the vector
y -- [page:Float] representing the y value of the vector
A vector in 2 dimensional space

Properties

[property:Float x]

[property:Float y]

Methods

[method:Vector2 set]( [page:Float x], [page:Float y] ) [page:Vector2 this]

Sets value of this vector.

[method:Vector2 setX]( [page:Float x] ) [page:Vector2 this]

x -- [page:Float]
replace this vector's x value with x.

[method:Vector2 setY]( [page:Float y] ) [page:Vector2 this]

y -- [page:Float]
replace this vector's y value with y.

[method:Vector2 copy]( [page:Vector2 v] ) [page:Vector2 this]

Copies value of *v* to this vector.

[method:Vector2 fromArray]( [page:Array array], [page:Integer offset] ) [page:Vector2 this]

array -- The source array of length 2
offset -- An optional offset into the array.
Sets this vector's x value to be array[0] and y value to be array[1].

[method:Vector2 add]( [page:Vector2 v] ) [page:Vector2 this]

Adds *v* to this vector.

[method:Vector2 addVectors]( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]

Sets this vector to *a + b*.

[method:Vector2 addScaledVector]( [page:Vector2 v], [page:Float s] ) [page:Vector2 this]

Adds the multiple of v and s to this vector.

[method:Vector2 sub]( [page:Vector2 v] ) [page:Vector2 this]

Subtracts *v* from this vector.

[method:Vector2 subVectors]( [page:Vector2 a], [page:Vector2 b] ) [page:Vector2 this]

Sets this vector to *a - b*.

[method:Vector2 multiplyScalar]( [page:Float s] ) [page:Vector2 this]

Multiplies this vector by scalar *s*.

[method:Vector2 divideScalar]( [page:Float s] ) [page:Vector2 this]

Divides this vector by scalar *s*.
Set vector to *( 0, 0 )* if *s == 0*.

[method:Vector2 negate]() [page:Vector2 this]

Inverts this vector.

[method:Float dot]( [page:Vector2 v] ) [page:Vector2 this]

Computes dot product of this vector and *v*.

[method:Float lengthSq]() [page:Vector2 this]

Computes squared length of this vector.

[method:Float length]() [page:Vector2 this]

Computes length of this vector.

[method:Float lengthManhattan]() [page:Vector2 this]

Computes Manhattan length of this vector.
[link:http://en.wikipedia.org/wiki/Taxicab_geometry]

[method:Vector2 normalize]() [page:Vector2 this]

Normalizes this vector.

[method:Float angle]() [page:Vector2 this]

Computes the angle in radians of this vector with respect to the positive x-axis.

[method:Float distanceTo]( [page:Vector2 v] )

Computes distance of this vector to *v*.

[method:Float distanceToSquared]( [page:Vector2 v] )

Computes squared distance of this vector to *v*.

[method:Vector2 setLength]( [page:Float l] ) [page:Vector2 this]

Normalizes this vector and multiplies it by *l*.

[method:Vector2 clamp]( [page:Vector2 min], [page:Vector2 max] ) [page:Vector2 this]

min -- [page:Vector2] containing the min x and y values in the desired range
max -- [page:Vector2] containing the max x and y values in the desired range
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.

[method:Vector2 clampScalar]( [page:Float min], [page:Float max] ) [page:Vector2 this]

min -- [page:Float] the minimum value the components will be clamped to
max -- [page:Float] the maximum value the components will be clamped to
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.

[method:Vector2 clampLength]( [page:Float min], [page:Float max] ) [page:Vector2 this]

min -- [page:Float] the minimum value the length will be clamped to
max -- [page:Float] the maximum value the length will be clamped to
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.

[method:Vector2 floor]() [page:Vector2 this]

The components of the vector are rounded downwards (towards negative infinity) to an integer value.

[method:Vector2 ceil]() [page:Vector2 this]

The components of the vector are rounded upwards (towards positive infinity) to an integer value.

[method:Vector2 round]() [page:Vector2 this]

The components of the vector are rounded towards the nearest integer value.

[method:Vector2 roundToZero]() [page:Vector2 this]

The components of the vector are rounded towards zero (up if negative, down if positive) to an integer value.

[method:Vector2 lerp]( [page:Vector2 v], [page:Float alpha] ) [page:Vector2 this]

v -- [page:Vector2]
alpha -- [page:Float] between 0 and 1;
Linear interpolation between this vector and v, where alpha is the percent along the line.

[method:Vector2 lerpVectors]( [page:Vector2 v1], [page:Vector2 v2], [page:Float alpha] ) [page:Vector2 this]

v1 -- [page:Vector2]
v2 -- [page:Vector2]
alpha -- [page:Float] between 0 and 1.
Sets this vector to be the vector linearly interpolated between *v1* and *v2* with *alpha* factor.

[method:undefined setComponent]( [page:Integer index], [page:Float value] ) [page:Vector2 this]

index -- 0 or 1
value -- [page:Float]
if index equals 0 method replaces this.x with value.
if index equals 1 method replaces this.y with value.

[method:Vector2 addScalar]( [page:Float s] ) [page:Vector2 this]

s -- [page:Float]
Add the scalar value s to this vector's x and y values.

[method:Float getComponent]( [page:Integer index] ) [page:Vector2 this]

index -- 0 or 1
if index equals 0 returns the x value.
if index equals 1 returns the y value.

[method:Vector2 min]( [page:Vector2 v] ) [page:Vector2 this]

v -- [page:Vector2]
If this vector's x or y value is greater than v's x or y value, replace that value with the corresponding min value.

[method:Vector2 max]( [page:Vector2 v] ) [page:Vector2 this]

v -- [page:Vector2]
If this vector's x or y value is less than v's x or y value, replace that value with the corresponding max value.

[method:Boolean equals]( [page:Vector2 v] ) [page:Vector2 this]

Checks for strict equality of this vector and *v*.

[method:Vector2 clone]() [page:Vector2 this]

Clones this vector.

[method:Array toArray]( [page:Array array], [page:Integer offset] ) [page:Vector2 this]

array -- An optional array to store the vector to.
offset -- An optional offset into the array.
Returns an array [x, y].

Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]