Skip to content

Documentation / base / Vector4

Class: Vector4

Defined in: libs/base/src/math/vector.ts:1189

4 dimentional vector

Extends

Extended by

Indexable

[index: number]: number

Constructors

Constructor

new Vector4(x, y, z, w): Vector4

Defined in: libs/base/src/math/vector.ts:1197

Creates a new Vector4 initialized with values.

Parameters

x

number

The x component.

y

number

The y component.

z

number

The z component.

w

number

The w component.

Returns

Vector4

Overrides

VectorBase.constructor

Constructor

new Vector4(elements): Vector4

Defined in: libs/base/src/math/vector.ts:1202

Creates a new Vector4 initialized with values in an array.

Parameters

elements

number[]

Array that contains the x, y, z, w values.

Returns

Vector4

Overrides

VectorBase.constructor

Constructor

new Vector4(array): Vector4

Defined in: libs/base/src/math/vector.ts:1207

Creates a new Vector4 initialized with values in a Float32Array.

Parameters

array

Float32Array

Float32Array object that contains the x, y, z, w values.

Returns

Vector4

Overrides

VectorBase.constructor

Constructor

new Vector4(buffer, offset): Vector4

Defined in: libs/base/src/math/vector.ts:1213

Creates a new Vector4 placed on a given ArrayBuffer object.

Parameters

buffer

ArrayBuffer

The array buffer object.

offset

number

The byte offset of the buffer where the vector placed at.

Returns

Vector4

Overrides

VectorBase.constructor

Constructor

new Vector4(): Vector4

Defined in: libs/base/src/math/vector.ts:1217

Creates a new Vector4 filled with zero values.

Returns

Vector4

Overrides

VectorBase.constructor

Accessors

x

Get Signature

get x(): number

Defined in: libs/base/src/math/vector.ts:1256

Get the x component value.

Returns

number

Set Signature

set x(v): void

Defined in: libs/base/src/math/vector.ts:1259

Parameters
v

number

Returns

void


y

Get Signature

get y(): number

Defined in: libs/base/src/math/vector.ts:1263

Get the y component value.

Returns

number

Set Signature

set y(v): void

Defined in: libs/base/src/math/vector.ts:1266

Parameters
v

number

Returns

void


z

Get Signature

get z(): number

Defined in: libs/base/src/math/vector.ts:1270

Get the z component value.

Returns

number

Set Signature

set z(v): void

Defined in: libs/base/src/math/vector.ts:1273

Parameters
v

number

Returns

void


w

Get Signature

get w(): number

Defined in: libs/base/src/math/vector.ts:1277

Get the w component value.

Returns

number

Set Signature

set w(v): void

Defined in: libs/base/src/math/vector.ts:1280

Parameters
v

number

Returns

void


magnitude

Get Signature

get magnitude(): number

Defined in: libs/base/src/math/vector.ts:1284

Get the length of the vector.

Returns

number


magnitudeSq

Get Signature

get magnitudeSq(): number

Defined in: libs/base/src/math/vector.ts:1288

Get the squared length of the vector.

Returns

number

Methods

equalsTo()

equalsTo(other, epsl?): boolean

Defined in: libs/base/src/math/vector.ts:31

Check if all data is close enough to another

Parameters

other

Float32Array<ArrayBuffer>

The data to be compared with.

epsl?

number

Returns

boolean

true if close enough, otherwise false.

Inherited from

VectorBase.equalsTo


toString()

toString(): string

Defined in: libs/base/src/math/vector.ts:51

Convert this to string object.

Returns

string

Inherited from

VectorBase.toString


isNaN()

isNaN(): boolean

Defined in: libs/base/src/math/vector.ts:60

Check the data for the presence of NaN.

Returns

boolean

true if NaN is present, otherwise false.

Inherited from

VectorBase.isNaN


setRandom()

setRandom(minValue, maxValue): void

Defined in: libs/base/src/math/vector.ts:74

Generate random vector

Parameters

minValue

number

Minimum value of any component of the vector

maxValue

number

Maximum value of any component of the vector

Returns

void

Inherited from

VectorBase.setRandom


clone()

clone(): Vector4

Defined in: libs/base/src/math/vector.ts:1252

Creates a new Vector4 initialized with values from this vector.

Returns

Vector4

The new vector.


xy()

xy(): Vector2

Defined in: libs/base/src/math/vector.ts:1295

Creates a new Vector2 initialized with x, y component of this vector.

Returns

Vector2

The new vector


xyz()

xyz(): Vector3

Defined in: libs/base/src/math/vector.ts:1302

Creates a new Vector3 initialized with x, y, z component of this vector.

Returns

Vector3

The new vector


setXYZW()

setXYZW(x, y, z, w): Vector4

Defined in: libs/base/src/math/vector.ts:1313

Set component values.

Parameters

x

number

The x component value.

y

number

The y component value.

z

number

The z component value.

w

number

The w component value.

Returns

Vector4

self


setAndNormalize()

setAndNormalize(x, y, z, w): Vector4

Defined in: libs/base/src/math/vector.ts:1328

Set component values and then normalize the vector.

Parameters

x

number

The x component value.

y

number

The y component value.

z

number

The z component value.

w

number

The w component value.

Returns

Vector4

self


subBy()

subBy(other): Vector4

Defined in: libs/base/src/math/vector.ts:1337

Subtract a vector from this vector.

Parameters

other

Vector4

The vector that will be subtract.

Returns

Vector4

self


addBy()

addBy(other): Vector4

Defined in: libs/base/src/math/vector.ts:1346

Add a vector to this vector.

Parameters

other

Vector4

The vector that will be added.

Returns

Vector4

self


combineBy()

combineBy(other, t0, t1): Vector4

Defined in: libs/base/src/math/vector.ts:1357

Combine a vector to this vector.

Parameters

other

Vector4

The vector that will be added.

t0

number

Scale factor for this vector

t1

number

Scale factor for other vector

Returns

Vector4

self


mulBy()

mulBy(other): Vector4

Defined in: libs/base/src/math/vector.ts:1366

Multiply this vector by a vector.

Parameters

other

Vector4

The vector that will be multiplied by.

Returns

Vector4

self


divBy()

divBy(other): Vector4

Defined in: libs/base/src/math/vector.ts:1375

Divide this vector by a vector.

Parameters

other

Vector4

The vector that will be divide by.

Returns

Vector4

self


scaleBy()

scaleBy(f): Vector4

Defined in: libs/base/src/math/vector.ts:1384

Scale this vector by a scalar number.

Parameters

f

number

amount to scale this vector by.

Returns

Vector4

self


inplaceNormalize()

inplaceNormalize(): Vector4

Defined in: libs/base/src/math/vector.ts:1392

Normalize this vector inplace.

Returns

Vector4

self


inplaceInverse()

inplaceInverse(): Vector4

Defined in: libs/base/src/math/vector.ts:1400

Inverse this vector inplace.

Returns

Vector4

self


inplaceMin()

inplaceMin(other): Vector4

Defined in: libs/base/src/math/vector.ts:1409

Set the component values to the minimum of this vector and another vector.

Parameters

other

Vector4

The vector that to be compared with.

Returns

Vector4

self


inplaceMax()

inplaceMax(other): Vector4

Defined in: libs/base/src/math/vector.ts:1418

Set the component values to the maximum of this vector and another vector.

Parameters

other

Vector4

The vector that to be compared with.

Returns

Vector4

self


zero()

static zero(): Vector4

Defined in: libs/base/src/math/vector.ts:1426

Creates a new Vector4 initialized with zero values.

Returns

Vector4

The new vector


one()

static one(): Vector4

Defined in: libs/base/src/math/vector.ts:1433

Creates a new Vector4 initialized with one.

Returns

Vector4

The new vector


axisPX()

static axisPX(): Vector4

Defined in: libs/base/src/math/vector.ts:1440

Creates a new Vector4 pointing in the positive direction of the X axis, i.e. vec4(1, 0, 0, 0)

Returns

Vector4

The new vector


axisNX()

static axisNX(): Vector4

Defined in: libs/base/src/math/vector.ts:1447

Creates a new Vector4 pointing in the negative direction of the X axis, i.e. vec4(-1, 0, 0, 0)

Returns

Vector4

The new vector


axisPY()

static axisPY(): Vector4

Defined in: libs/base/src/math/vector.ts:1454

Creates a new Vector4 pointing in the positive direction of the Y axis, i.e. vec4(0, 1, 0, 0)

Returns

Vector4

The new vector


axisNY()

static axisNY(): Vector4

Defined in: libs/base/src/math/vector.ts:1461

Creates a new Vector4 pointing in the negative direction of the Y axis, i.e. vec4(0, -1, 0, 0)

Returns

Vector4

The new vector


axisPZ()

static axisPZ(): Vector4

Defined in: libs/base/src/math/vector.ts:1468

Creates a new Vector4 pointing in the positive direction of the Z axis, i.e. vec4(0, 0, 1, 0)

Returns

Vector4

The new vector


axisNZ()

static axisNZ(): Vector4

Defined in: libs/base/src/math/vector.ts:1475

Creates a new Vector4 pointing in the negative direction of the Z axis, i.e. vec4(0, 0, -1, 0)

Returns

Vector4

The new vector


axisPW()

static axisPW(): Vector4

Defined in: libs/base/src/math/vector.ts:1482

Creates a new Vector4 pointing in the positive direction of the W axis, i.e. vec4(0, 0, 0, 1)

Returns

Vector4

The new vector


axisNW()

static axisNW(): Vector4

Defined in: libs/base/src/math/vector.ts:1489

Creates a new Vector4 pointing in the negative direction of the W axis, i.e. vec4(0, 0, 0, -1)

Returns

Vector4

The new vector


normalize()

static normalize(v, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1498

Normalize a Vector4

Parameters

v

Vector4

The input vector

result?

Vector4

The output vector (can be the same as v). if not specified, a new vector will be created.

Returns

Vector4

The output vector


inverse()

static inverse(v, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1512

Inverse a Vector4

Parameters

v

Vector4

The input vector

result?

Vector4

The output vector (can be the same vector as v). if not specified, a new vector will be created.

Returns

Vector4

The output vector


sub()

static sub(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1526

Subtract two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


add()

static add(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1540

Add two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


combine()

static combine(a, b, t0, t1, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1556

Combine two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

t0

number

Scale factor for the first operand

t1

number

Scale factor for the second operand

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


lerp()

static lerp(a, b, t, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1571

Linearly interpolate between two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

t

number

The interpolation factor. The result is equal to a when t = 0 and equal to b when t = 1.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


mul()

static mul(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1585

Multiply two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


div()

static div(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1599

Divide two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


scale()

static scale(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1613

Scale a Vector4 by a scalar number.

Parameters

a

Vector4

The vector to be scaled.

b

number

The scalar number.

result?

Vector4

The output vector (can be the same vector as a). if not specified, a new vector will be created.

Returns

Vector4

The output vector


min()

static min(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1627

Calculates the minimum of two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


max()

static max(a, b, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1641

Calculates the maximum of two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


abs()

static abs(a, result?): Vector4

Defined in: libs/base/src/math/vector.ts:1654

Calculates the absolute values of a Vector4.

Parameters

a

Vector4

The input vector.

result?

Vector4

The output vector (can be the same vector as a or b). if not specified, a new vector will be created.

Returns

Vector4

The output vector


dot()

static dot(a, b): number

Defined in: libs/base/src/math/vector.ts:1667

Calculates the dot product of two Vector4's.

Parameters

a

Vector4

The first operand.

b

Vector4

The second operand.

Returns

number

dot product of a and b

Released under the MIT License.