Options
All
• Public
• Public/Protected
• All

# Namespace vec2

## Functions

• Adds two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### angle

• Get the angle between two 2D vectors

#### Parameters

• ##### a: ReadonlyVec2

The first operand

• ##### b: ReadonlyVec2

The second operand

#### Returns number

The angle in radians

### ceil

• ceil(out: vec2, a: ReadonlyVec2): vec2
• Math.ceil the components of a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to ceil

out

### clone

• clone(a: ReadonlyVec2): vec2
• Creates a new vec2 initialized with values from an existing vector

#### Parameters

• ##### a: ReadonlyVec2

vector to clone

#### Returns vec2

a new 2D vector

### copy

• copy(out: vec2, a: ReadonlyVec2): vec2
• Copy the values from one vec2 to another

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the source vector

out

### create

• Creates a new, empty vec2

#### Returns vec2

a new 2D vector

### cross

• cross(out: vec3, a: ReadonlyVec2, b: ReadonlyVec2): vec3
• Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

#### Parameters

• ##### out: vec3

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### dist

• Calculates the euclidian distance between two vec2's

#### Parameters

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

#### Returns number

distance between a and b

### distance

• Calculates the euclidian distance between two vec2's

#### Parameters

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

#### Returns number

distance between a and b

### div

• div(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Divides two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### divide

• divide(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Divides two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### dot

• Calculates the dot product of two vec2's

#### Parameters

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

#### Returns number

dot product of a and b

### equals

• Returns whether or not the vectors have approximately the same elements in the same position.

#### Parameters

• ##### a: ReadonlyVec2

The first vector.

• ##### b: ReadonlyVec2

The second vector.

#### Returns boolean

True if the vectors are equal, false otherwise.

### exactEquals

• Returns whether or not the vectors exactly have the same elements in the same position (when compared with ===)

#### Parameters

• ##### a: ReadonlyVec2

The first vector.

• ##### b: ReadonlyVec2

The second vector.

#### Returns boolean

True if the vectors are equal, false otherwise.

### floor

• floor(out: vec2, a: ReadonlyVec2): vec2
• Math.floor the components of a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to floor

out

### forEach

• forEach(a: any, stride: any, offset: any, count: any, fn: any, arg: any): any

### fromValues

• fromValues(x: number, y: number): vec2
• Creates a new vec2 initialized with the given values

#### Parameters

• ##### x: number

X component

• ##### y: number

Y component

#### Returns vec2

a new 2D vector

### inverse

• inverse(out: vec2, a: ReadonlyVec2): vec2
• Returns the inverse of the components of a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to invert

out

### len

• len(a: ReadonlyVec2): number
• Calculates the length of a vec2

#### Parameters

• ##### a: ReadonlyVec2

vector to calculate length of

length of a

### length

• length(a: ReadonlyVec2): number
• Calculates the length of a vec2

#### Parameters

• ##### a: ReadonlyVec2

vector to calculate length of

length of a

### lerp

• lerp(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, t: number): vec2
• Performs a linear interpolation between two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

• ##### t: number

interpolation amount, in the range [0-1], between the two inputs

out

### max

• max(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Returns the maximum of two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### min

• min(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Returns the minimum of two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### mul

• mul(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Multiplies two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### multiply

• multiply(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Multiplies two vec2's

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### negate

• negate(out: vec2, a: ReadonlyVec2): vec2
• Negates the components of a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to negate

out

### normalize

• normalize(out: vec2, a: ReadonlyVec2): vec2
• Normalize a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to normalize

out

### random

• random(out: vec2, scale?: number): vec2
• Generates a random vector with the given scale

#### Parameters

• ##### out: vec2

the receiving vector

out

### rotate

• rotate(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, rad: number): vec2
• Rotate a 2D vector

#### Parameters

• ##### out: vec2

The receiving vec2

• ##### a: ReadonlyVec2

The vec2 point to rotate

• ##### b: ReadonlyVec2

The origin of the rotation

• ##### rad: number

The angle of rotation in radians

out

### round

• round(out: vec2, a: ReadonlyVec2): vec2
• Math.round the components of a vec2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

vector to round

out

### scale

• scale(out: vec2, a: ReadonlyVec2, b: number): vec2
• Scales a vec2 by a scalar number

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the vector to scale

• ##### b: number

amount to scale the vector by

#### Returns vec2

out

• scaleAndAdd(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2, scale: number): vec2
• Adds two vec2's after scaling the second operand by a scalar value

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

• ##### scale: number

the amount to scale b by before adding

out

### set

• set(out: vec2, x: number, y: number): vec2
• Set the components of a vec2 to the given values

#### Parameters

• ##### out: vec2

the receiving vector

• ##### x: number

X component

• ##### y: number

Y component

out

### sqrDist

• Calculates the squared euclidian distance between two vec2's

#### Parameters

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

#### Returns number

squared distance between a and b

### sqrLen

• sqrLen(a: ReadonlyVec2): number
• Calculates the squared length of a vec2

#### Parameters

• ##### a: ReadonlyVec2

vector to calculate squared length of

#### Returns number

squared length of a

### squaredDistance

• Calculates the squared euclidian distance between two vec2's

#### Parameters

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

#### Returns number

squared distance between a and b

### squaredLength

• squaredLength(a: ReadonlyVec2): number
• Calculates the squared length of a vec2

#### Parameters

• ##### a: ReadonlyVec2

vector to calculate squared length of

#### Returns number

squared length of a

### str

• str(a: ReadonlyVec2): string
• Returns a string representation of a vector

#### Parameters

• ##### a: ReadonlyVec2

vector to represent as a string

#### Returns string

string representation of the vector

### sub

• sub(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Subtracts vector b from vector a

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### subtract

• subtract(out: vec2, a: ReadonlyVec2, b: ReadonlyVec2): vec2
• Subtracts vector b from vector a

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the first operand

• ##### b: ReadonlyVec2

the second operand

out

### transformMat2

• transformMat2(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2): vec2
• Transforms the vec2 with a mat2

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the vector to transform

• ##### m: ReadonlyMat2

matrix to transform with

out

### transformMat2d

• transformMat2d(out: vec2, a: ReadonlyVec2, m: ReadonlyMat2d): vec2
• Transforms the vec2 with a mat2d

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the vector to transform

• ##### m: ReadonlyMat2d

matrix to transform with

out

### transformMat3

• transformMat3(out: vec2, a: ReadonlyVec2, m: ReadonlyMat3): vec2
• Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the vector to transform

• ##### m: ReadonlyMat3

matrix to transform with

out

### transformMat4

• transformMat4(out: vec2, a: ReadonlyVec2, m: ReadonlyMat4): vec2
• Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

#### Parameters

• ##### out: vec2

the receiving vector

• ##### a: ReadonlyVec2

the vector to transform

• ##### m: ReadonlyMat4

matrix to transform with

out

### zero

• Set the components of a vec2 to zero

#### Parameters

• ##### out: vec2

the receiving vector

out