Skip to content

Class: Vector2

Vector 2D

Constructors

Properties

Methods

Constructors

constructor

new Vector2(x?, y?)

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.

Defined in

src/math/Vector2.ts:39

Properties

ZERO

Static Readonly ZERO: Vector2

Defined in

src/math/Vector2.ts:18


SAFE_MAX

Static Readonly SAFE_MAX: Vector2

Defined in

src/math/Vector2.ts:20


SAFE_MIN

Static Readonly SAFE_MIN: Vector2

Defined in

src/math/Vector2.ts:22


x

x: number = 0.0

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

Defined in

src/math/Vector2.ts:27


y

y: number = 0.0

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

Defined in

src/math/Vector2.ts:32

Methods

getAngle

Static 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:50


slerp

Static 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:60


lerp

Static 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:89


set

set(x?, y?): Vector2

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

Vector2

Defined in

src/math/Vector2.ts:102


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:113


add

add(a, target?): Vector2

Add the vectors.

Parameters

NameType
aVector2
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:123


sub

sub(a, target?): Vector2

Vector subtraction

Parameters

NameType
aVector2
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:136


scale

scale(v): Vector2

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

Parameters

NameType
vnumber

Returns

Vector2

Defined in

src/math/Vector2.ts:147


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:159


multiplyScaler

multiplyScaler(a): Vector2

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

Parameters

NameType
anumber

Returns

Vector2

Defined in

src/math/Vector2.ts:172


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:183


neg

neg(target?): Vector2

Vector inversion

Parameters

NameType
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:195


abs

abs(): number

Returns

number

Defined in

src/math/Vector2.ts:202


length

length(): number

Length of vector

Returns

number

Defined in

src/math/Vector2.ts:210


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:219


unt

unt(target?): Vector2

Parameters

NameType
target?Vector2

Returns

Vector2

Defined in

src/math/Vector2.ts:223


angleTo

angleTo(v): number

Parameters

NameType
vVector2

Returns

number

Defined in

src/math/Vector2.ts:231


equals

equals(a): boolean

Whether two vectors are equal

Parameters

NameTypeDescription
aVector2Vector of comparison

Returns

boolean

Defined in

src/math/Vector2.ts:242


pal

pal(a): number

Parameters

NameType
aVector2

Returns

number

Defined in

src/math/Vector2.ts:247


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:259


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:268


dot

dot(value): number

Take the dot product of two vectors.

Parameters

NameTypeDescription
valueVector2Target vector

Returns

number

Defined in

src/math/Vector2.ts:279


normalize

normalize(): Vector2

Convert this vector to a unit vector.

Returns

Vector2

Defined in

src/math/Vector2.ts:286


addInPlace

addInPlace(otherVector): Vector2

Add two vectors

Parameters

NameTypeDescription
otherVectorVector2Additive vector

Returns

Vector2

Defined in

src/math/Vector2.ts:298


addScalar

addScalar(s): Vector2

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

Parameters

NameTypeDescription
snumberAdditive scalar

Returns

Vector2

Defined in

src/math/Vector2.ts:309


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:322