Vector2

2D vector.

Example

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

Constructor

Vector2( x, y )

x -- Float representing the x value of the vector
y -- Float representing the y value of the vector
A vector in 2 dimensional space

Properties

.x

.y

Methods

.set ( x, y ) this

Sets value of this vector.

.setX ( x ) this

x -- Float
replace this vector's x value with x.

.setY ( y ) this

y -- Float
replace this vector's y value with y.

.copy ( v ) this

Copies value of v to this vector.

.fromArray ( array, offset ) 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].

.add ( v ) this

Adds v to this vector.

.addVectors ( a, b ) this

Sets this vector to a + b.

.addScaledVector ( v, s ) this

Adds the multiple of v and s to this vector.

.sub ( v ) this

Subtracts v from this vector.

.subVectors ( a, b ) this

Sets this vector to a - b.

.multiplyScalar ( s ) this

Multiplies this vector by scalar s.

.divideScalar ( s ) this

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

.negate () this

Inverts this vector.

.dot ( v ) this

Computes dot product of this vector and v.

.lengthSq () this

Computes the squared length of this vector.

.length () this

Computes the length of this vector.

.lengthManhattan () this

Computes the Manhattan length of this vector.
http://en.wikipedia.org/wiki/Taxicab_geometry

.normalize () this

Normalizes this vector.

.angle () this

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

.distanceTo ( v )

Computes the distance from this vector to v.

.distanceToSquared ( v )

Computes the squared distance from this vector to v.

.distanceToManhattan ( v )

Computes the Manhattan distance from this vector to v.

.setLength ( l ) this

Normalizes this vector and multiplies it by l.

.clamp ( min, max ) this

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

.clampScalar ( min, max ) this

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

.clampLength ( min, max ) this

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

.floor () this

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

.ceil () this

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

.round () this

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

.roundToZero () this

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

.lerp ( v, alpha ) this

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

.lerpVectors ( v1, v2, alpha ) this

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

.setComponent ( index, value ) this

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

.addScalar ( s ) this

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

.getComponent ( index ) this

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

.min ( v ) this

v -- 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.

.max ( v ) this

v -- 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.

.equals ( v ) this

Checks for strict equality of this vector and v.

.clone () this

Clones this vector.

.toArray ( array, offset ) this

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

Source

src/math/Vector2.js
Edit