Skip to content
On this page

Class: Vector2

WebSG.Vector2

A 2-dimensional vector.

Indexable

▪ [index: number]: number

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Vector2()

Constructs a new vector.

Defined in

websg.d.ts:1856

new Vector2(x, y)

Constructs a new vector with the given components.

Parameters

NameTypeDescription
xnumberThe x component.
ynumberThe y component.

Defined in

websg.d.ts:1862

new Vector2(array)

Constructs and sets the initial components of the vector from a numeric array-like object.

Parameters

NameType
arrayArrayLike<number>

Defined in

websg.d.ts:1866

Properties

length

Readonly length: number

Returns the number of components in this vector.

Defined in

websg.d.ts:1943


x

x: number

The x component of the vector.

Defined in

websg.d.ts:1848


y

y: number

The y component of the vector.

Defined in

websg.d.ts:1852

Methods

add

add(vector): Vector2

Adds the given vector to this vector.

Parameters

NameTypeDescription
vectorArrayLike<number>The vector to add.

Returns

Vector2

Defined in

websg.d.ts:1880


addScaledVector

addScaledVector(vector, scale): Vector2

Adds the given vector scaled by the given scalar to this vector.

Parameters

NameType
vectorArrayLike<number>
scalenumber

Returns

Vector2

Defined in

websg.d.ts:1890


addVectors

addVectors(a, b): Vector2

Adds the given vectors together and stores the result in this vector.

Parameters

NameTypeDescription
aArrayLike<number>The first vector.
bArrayLike<number>The second vector.

Returns

Vector2

Defined in

websg.d.ts:1886


divide

divide(vector): Vector2

Divides this vector by the given vector.

Parameters

NameTypeDescription
vectorArrayLike<number>The vector to divide by.

Returns

Vector2

Defined in

websg.d.ts:1928


divideScalar

divideScalar(scalar): Vector2

Divides this vector by the given scalar.

Parameters

NameTypeDescription
scalarnumberThe scalar to divide by.

Returns

Vector2

Defined in

websg.d.ts:1939


divideVectors

divideVectors(a, b): Vector2

Divides the given vectors and stores the result in this vector.

Parameters

NameTypeDescription
aArrayLike<number>The first vector.
bArrayLike<number>The second vector.

Returns

Vector2

Defined in

websg.d.ts:1934


multiply

multiply(vector): Vector2

Multiplies this vector by the given vector.

Parameters

NameTypeDescription
vectorArrayLike<number>The vector to multiply by.

Returns

Vector2

Defined in

websg.d.ts:1912


multiplyScalar

multiplyScalar(scalar): Vector2

Multiplies this vector by the given scalar.

Parameters

NameTypeDescription
scalarnumberThe scalar to multiply by.

Returns

Vector2

Defined in

websg.d.ts:1923


multiplyVectors

multiplyVectors(a, b): Vector2

Multiplies the given vectors together and stores the result in this vector.

Parameters

NameTypeDescription
aArrayLike<number>The first vector.
bArrayLike<number>The second vector.

Returns

Vector2

Defined in

websg.d.ts:1918


set

set(value): Vector2

Sets the components of the vector.

Parameters

NameTypeDescription
valueArrayLike<number>The x,y components of the vector.

Returns

Vector2

Defined in

websg.d.ts:1871


setScalar

setScalar(value): Vector2

Sets the components of the vector to a scalar value.

Parameters

NameType
valuenumber

Returns

Vector2

Defined in

websg.d.ts:1875


subtract

subtract(vector): Vector2

Subtracts the given vector from this vector.

Parameters

NameTypeDescription
vectorArrayLike<number>The vector to subtract.

Returns

Vector2

Defined in

websg.d.ts:1895


subtractScaledVector

subtractScaledVector(vector, scale): Vector2

Subtracts the given vector scaled by the given scalar from this vector.

Parameters

NameTypeDescription
vectorArrayLike<number>The vector to subtract.
scalenumberThe scalar to scale the vector by.

Returns

Vector2

Defined in

websg.d.ts:1907


subtractVectors

subtractVectors(a, b): Vector2

Subtracts the second vector from the first and stores the result in this vector.

Parameters

NameTypeDescription
aArrayLike<number>The first vector.
bArrayLike<number>The second vector.

Returns

Vector2

Defined in

websg.d.ts:1901