Options
All
• Public
• Public/Protected
• All

# Class Vector2

Serializable THREE.js Vector2

• Vector2
• Vector2

## Constructors

### constructor

• new Vector2(x?: number, y?: number): Vector2

height: number

isVector2: true

width: number

x: number

y: number

## Methods

• add(v: Vector2, w?: Vector2): Vector2
• Adds v to this vector.

#### Returns Vector2

• Adds the scalar value s to this vector's x and y values.

#### Returns Vector2

• addScaledVector(v: Vector2, s: number): Vector2
• Adds the multiple of v and s to this vector.

#### Returns Vector2

• addVectors(a: Vector2, b: Vector2): Vector2
• Sets this vector to a + b.

### angle

• angle(): number
• computes the angle in radians with respect to the positive x-axis

### applyMatrix3

• applyMatrix3(m: Matrix3): Vector2
• Multiplies this vector (with an implicit 1 as the 3rd component) by m.

### ceil

• The x and y components of the vector are rounded up to the nearest integer value.

### clamp

• clamp(min: Vector2, max: Vector2): Vector2
• 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.

#### Parameters

• ##### min: Vector2

the minimum x and y values.

• ##### max: Vector2

the maximum x and y values in the desired range.

### clampLength

• clampLength(min: number, max: number): Vector2
• 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.

#### Parameters

• ##### min: number

the minimum value the length will be clamped to.

• ##### max: number

the maximum value the length will be clamped to.

### clampScalar

• clampScalar(min: number, max: number): Vector2
• 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.

#### Parameters

• ##### min: number

the minimum value the components will be clamped to.

• ##### max: number

the maximum value the components will be clamped to.

### copy

• Copies value of v to this vector.

### cross

• cross(v: Vector2): number
• Computes cross product of this vector and v.

### distanceTo

• distanceTo(v: Vector2): number
• Computes distance of this vector to v.

### distanceToManhattan

• distanceToManhattan(v: Vector2): number
• deprecated

### distanceToSquared

• distanceToSquared(v: Vector2): number
• Computes squared distance of this vector to v.

### divide

• Divides this vector by v.

### divideScalar

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

### dot

• dot(v: Vector2): number
• Computes dot product of this vector and v.

### equals

• equals(v: Vector2): boolean
• Checks for strict equality of this vector and v.

### floor

• The components of the vector are rounded down to the nearest integer value.

### fromArray

• fromArray(array: number[] | ArrayLike<number>, offset?: number): Vector2
• Sets this vector's x and y value from the provided array or array-like.

#### Parameters

• ##### array: number[] | ArrayLike<number>

the source array or array-like.

• ##### Optional offset: number

(optional) offset into the array. Default is 0.

### fromBufferAttribute

• fromBufferAttribute(attribute: BufferAttribute, index: number): Vector2
• Sets this vector's x and y values from the attribute.

#### Parameters

• ##### attribute: BufferAttribute

the source attribute.

• ##### index: number

index in the attribute.

### getComponent

• getComponent(index: number): number
• Gets a component of this vector.

### length

• length(): number
• Computes length of this vector.

### lengthManhattan

• lengthManhattan(): number
• deprecated

### lengthSq

• lengthSq(): number
• Computes squared length of this vector.

### lerp

• lerp(v: Vector2, alpha: number): Vector2
• Linearly interpolates between this vector and v, where alpha is the distance along the line - alpha = 0 will be this vector, and alpha = 1 will be v.

#### Parameters

• ##### v: Vector2

vector to interpolate towards.

• ##### alpha: number

interpolation factor in the closed interval [0, 1].

### lerpVectors

• lerpVectors(v1: Vector2, v2: Vector2, alpha: number): Vector2
• Sets this vector to be the vector linearly interpolated between v1 and v2 where alpha is the distance along the line connecting the two vectors - alpha = 0 will be v1, and alpha = 1 will be v2.

#### Parameters

• ##### v1: Vector2

the starting vector.

• ##### v2: Vector2

vector to interpolate towards.

• ##### alpha: number

interpolation factor in the closed interval [0, 1].

### manhattanDistanceTo

• manhattanDistanceTo(v: Vector2): number
• Computes the Manhattan length (distance) from this vector to the given vector v

### manhattanLength

• manhattanLength(): number
• Computes the Manhattan length of this vector.

### max

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

### min

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

### multiply

• Multiplies this vector by v.

### multiplyScalar

• multiplyScalar(scalar: number): Vector2
• Multiplies this vector by scalar s.

### negate

• Inverts this vector.

### normalize

• Normalizes this vector.

### random

• Sets this vector's x and y from Math.random

### rotateAround

• rotateAround(center: Vector2, angle: number): Vector2
• Rotates the vector around center by angle radians.

#### Parameters

• ##### center: Vector2

the point around which to rotate.

• ##### angle: number

the angle to rotate, in radians.

### round

• The components of the vector are rounded to the nearest integer value.

### roundToZero

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

### set

• set(x: number, y: number): Vector2
• Sets value of this vector.

### setComponent

• setComponent(index: number, value: number): Vector2
• Sets a component of this vector.

### setLength

• setLength(length: number): Vector2
• Normalizes this vector and multiplies it by l.

### setScalar

• setScalar(scalar: number): Vector2
• Sets the x and y values of this vector both equal to scalar.

### setX

• Sets X component of this vector.

### setY

• Sets Y component of this vector.

### sub

• Subtracts v from this vector.

### subScalar

• Subtracts s from this vector's x and y components.

### subVectors

• subVectors(a: Vector2, b: Vector2): Vector2
• Sets this vector to a - b.

### toArray

• toArray(array?: number[], offset?: number): number[]
• toArray(array?: Vector2Tuple, offset?: 0): Vector2Tuple
• toArray(array: ArrayLike<number>, offset?: number): ArrayLike<number>
• Returns an array [x, y], or copies x and y into the provided array.

#### Parameters

• ##### Optional array: number[]

(optional) array to store the vector to. If this is not provided, a new array will be created.

• ##### Optional offset: number

(optional) optional offset into the array.

#### Returns number[]

The created or provided array.

#### Returns Vector2Tuple

• Copies x and y into the provided array-like.

#### Parameters

• ##### array: ArrayLike<number>

array-like to store the vector to.

• ##### Optional offset: number

(optional) optional offset into the array.

#### Returns ArrayLike<number>

The provided array-like.

### Static fromArray

• fromArray(array: number[]): Vector2