Skip to content

Class: Vector2

Vector 2D

Constructors

Properties

Methods

Constructors

constructor

new Vector2(x?, y?): Vector2

Create a new Vector2.

Parameters

NameTypeDefault valueDescription
xnumber0The x component of the vector, which defaults to 0.
ynumber0The y component of the vector, which defaults to 0.

Returns

Vector2

Defined in

src/math/Vector2.ts:44

Properties

ZERO

Static Readonly ZERO: Vector2

Defined in

src/math/Vector2.ts:23


SAFE_MAX

Static Readonly SAFE_MAX: Vector2

Defined in

src/math/Vector2.ts:25


SAFE_MIN

Static Readonly SAFE_MIN: Vector2

Defined in

src/math/Vector2.ts:27


x

x: number = 0.0

The x component of the vector, the default value is 0.

Defined in

src/math/Vector2.ts:32


y

y: number = 0.0

The y component of the vector, the default value is 0.

Defined in

src/math/Vector2.ts:37

Methods

getAngle

getAngle(a, b): number

Returns the Angle, in radians, between two vectors.

Parameters

NameTypeDescription
aVector2Vector a
bVector2Vector b

Returns

number

result

Defined in

src/math/Vector2.ts:55


slerp

slerp(from, to, t): Vector2

Computes linear interpolation between two vectors.

Parameters

NameTypeDescription
fromVector2starting vector
toVector2The vector in which you interpolate
tnumber

Returns

Vector2

Defined in

src/math/Vector2.ts:65


lerp

lerp(from, to, t): Vector2

Linear interpolation between two vectors.

Parameters

NameTypeDescription
fromVector2starting vector
toVector2The vector in which you interpolate
tnumber

Returns

Vector2

Defined in

src/math/Vector2.ts:94


set

set(x?, y?): this

Sets the x and y components of this vector.

Parameters

NameTypeDefault valueDescription
xnumber0The x component of the vector, which defaults to 0.
ynumber0The y component of the vector, which defaults to 0.

Returns

this

Defined in

src/math/Vector2.ts:107


distance

distance(a): number

Calculate the distance between this vector and the incoming vector.

Parameters

NameTypeDescription
aVector2Target vector

Returns

number

Defined in

src/math/Vector2.ts:118


add

add(a, target?): Vector2

Add the vectors.

Parameters

NameType
aVector2
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:128


sub

sub(a, target?): Vector2

Vector subtraction

Parameters

NameType
aVector2
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:141


scale

scale(v): this

Let's multiply the x and y values of this vector times v.

Parameters

NameType
vnumber

Returns

this

Defined in

src/math/Vector2.ts:152


multiply

multiply(a, target?): Vector2

Let's multiply the x and y values of this vector by a.

Parameters

NameType
anumber
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:164


multiplyScaler

multiplyScaler(a): this

Let's multiply the x and y values of this vector by a.

Parameters

NameType
anumber

Returns

this

Defined in

src/math/Vector2.ts:177


divide

divide(v, target?): Vector2

We're going to divide the x and y values of this vector by v.

Parameters

NameType
vnumber
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:188


neg

neg(target?): Vector2

Vector inversion

Parameters

NameType
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:200


abs

abs(): number

Returns

number

Defined in

src/math/Vector2.ts:207


length

length(): number

Length of vector

Returns

number

Defined in

src/math/Vector2.ts:215


getAngle

getAngle(target): number

Returns the Angle, in radians, between the current vector and the target vector.

Parameters

NameTypeDescription
targetVector2Target vector

Returns

number

Defined in

src/math/Vector2.ts:224


unt

unt(target?): Vector2

Parameters

NameType
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:228


angleTo

angleTo(v): number

Parameters

NameType
vVector2

Returns

number

Defined in

src/math/Vector2.ts:236


equals

equals(a): boolean

Whether two vectors are equal

Parameters

NameTypeDescription
aVector2Vector of comparison

Returns

boolean

Defined in

src/math/Vector2.ts:247


pal

pal(a): number

Parameters

NameType
aVector2

Returns

number

Defined in

src/math/Vector2.ts:252


clone

clone(): Vector2

Returns a new vector that has the same x and y as the current vector.

Returns

Vector2

Defined in

src/math/Vector2.ts:264


copyFrom

copyFrom(v): Vector2

Copy the x and y properties of the source vector to this vector

Parameters

NameTypeDescription
vVector2Source vector

Returns

Vector2

Defined in

src/math/Vector2.ts:273


dot

dot(value): number

Take the dot product of two vectors.

Parameters

NameTypeDescription
valueVector2Target vector

Returns

number

Defined in

src/math/Vector2.ts:284


normalize

normalize(): this

Convert this vector to a unit vector.

Returns

this

Defined in

src/math/Vector2.ts:291


addInPlace

addInPlace(otherVector): this

Add two vectors

Parameters

NameTypeDescription
otherVectorVector2Additive vector

Returns

this

Defined in

src/math/Vector2.ts:303


addScalar

addScalar(s): this

Add the scalar to the x and y of this vector.

Parameters

NameTypeDescription
snumberAdditive scalar

Returns

this

Defined in

src/math/Vector2.ts:314


clampScalar

clampScalar(minVal, maxVal): Vector2

Parameters

NameTypeDescription
minValnumberComponent will be limited to the minimum value of
maxValnumberThe component will be limited to the maximum value of

Returns

Vector2

Defined in

src/math/Vector2.ts:327