Options
All
• Public
• Public/Protected
• All

# Class Vec4

Representation of four-dimensional vectors.

## Constructors

### constructor

• newVec4(other: Vec4): Vec4
• newVec4(x?: undefined | number, y?: undefined | number, z?: undefined | number, w?: undefined | number): Vec4

## Properties

w: number

w component.

x: number

x component.

y: number

y component.

z: number

z component.

### Static NEGONE

NEGONE: {} = Object.freeze(new Vec4(-1, -1, -1, -1))

### Static ONE

ONE: {} = Object.freeze(new Vec4(1, 1, 1, 1))

### Static ZERO

ZERO: {} = Object.freeze(new Vec4(0, 0, 0, 0))

## Methods

• Adds the current vector with another one and return this

#### Parameters

• ##### other: Vec4

specified vector

#### Returns this

• add4f(x: number, y: number, z: number, w: number): this
• Adds the current vector with another one and return this

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

### clampf

• clampf(minInclusive: Vec4, maxInclusive: Vec4): this
• Clamp the vector between minInclusive and maxInclusive.

#### Parameters

• ##### minInclusive: Vec4

Minimum value allowed

• ##### maxInclusive: Vec4

Maximum value allowed

#### Returns this

`this`

### cross

• cross(vector: Vec4): this
• Calculates the cross product with another vector.

### divide

• divide(other: Vec4): this
• Element-wisely divides this vector with another one, and return this.

#### Parameters

• ##### other: Vec4

specified vector

### divide4f

• divide4f(x: number, y: number, z: number, w: number): this
• Element-wisely divides this vector with another one, and return this.

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

### dot

• dot(vector: Vec4): number
• Calculates the dot product with another vector

#### Returns number

当前向量与指定向量点乘的结果。

### equals

• equals(other: Vec4, epsilon?: number): boolean
• Check whether the vector approximately equals another one.

#### Parameters

• ##### other: Vec4

Specified vector

• ##### Default value epsilon: number = EPSILON

The error allowed. It`s should be a non-negative number.

#### Returns boolean

Returns `true` when the components of both vectors are equal within the specified range of error; otherwise it returns `false`.

### equals4f

• equals4f(x: number, y: number, z: number, w: number, epsilon?: number): boolean
• Check whether the vector approximately equals another one.

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

• ##### Default value epsilon: number = EPSILON

The error allowed. It`s should be a non-negative number.

#### Returns boolean

Returns `true` when the components of both vectors are equal within the specified range of error; otherwise it returns `false`.

### length

• length(): number

### lengthSqr

• lengthSqr(): number
• Returns the squared length of this vector.

#### Returns number

the squared length of this vector

### lerp

• lerp(to: Vec4, ratio: number): this
• Calculate linear interpolation result between this vector and another one with given ratio.

#### Parameters

• ##### to: Vec4

Target vector

• ##### ratio: number

The interpolation coefficient.The range is [0,1].

### multiply

• multiply(other: Vec4): this
• Multiplies the current vector with another one and return this

#### Parameters

• ##### other: Vec4

specified vector

### multiply4f

• multiply4f(x: number, y: number, z: number, w: number): this
• Multiplies the current vector with another one and return this

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

### multiplyScalar

• multiplyScalar(scalar: number): this
• Multiplies the current vector with a number, and returns this.

#### Parameters

• ##### scalar: number

scalar number

### negative

• negative(): this

### normalize

• normalize(): this

### set

• set(other: Vec4): any
• set(x?: undefined | number, y?: undefined | number, z?: undefined | number, w?: undefined | number): any
• Set the current vector value with the given vector.

#### Parameters

• ##### other: Vec4

Specified vector

#### Returns any

`this`

• Set the value of each component of the current vector.

x value

y value

z value

w value

#### Returns any

`this`

### strictEquals

• strictEquals(other: Vec4): boolean
• Check whether the current vector strictly equals another Vec4.

#### Parameters

• ##### other: Vec4

specified vector

#### Returns boolean

Returns `true` when the components of both vectors are equal within the specified range of error; otherwise it returns `false`.

### strictEquals4f

• strictEquals4f(x: number, y: number, z: number, w: number): boolean
• Check whether the current vector strictly equals another Vec4.

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

#### Returns boolean

Returns `true` when the components of both vectors are equal within the specified range of error; otherwise it returns `false`.

### subtract

• subtract(other: Vec4): this
• Subtracts one vector from this, and returns this.

#### Parameters

• ##### other: Vec4

specified vector

### subtract4f

• subtract4f(x: number, y: number, z: number, w: number): this
• Subtracts one vector from this, and returns this.

#### Parameters

• ##### x: number

The x value of specified vector

• ##### y: number

The y value of specified vector

• ##### z: number

The z value of specified vector

• ##### w: number

The w value of specified vector

### toString

• toString(): string

### transformMat4

• transformMat4(matrix: Mat4): this
• Transforms the vec4 with a mat4

#### Parameters

• ##### matrix: Mat4

matrix to transform with

#### Returns this

• add<Out>(out: Out, a: Out, b: Out): Out
• Element-wise vector addition and save the results to out vector object

### Static ceil

• ceil<Out>(out: Out, a: Out): Out
• Rounds up by elements of the vector and save the results to out vector object

### Static clone

• clone<Out>(a: Out): Vec4
• Obtains a clone of the given vector object

### Static copy

• copy<Out>(out: Out, a: Out): Out
• Copy the target vector and save the results to out vector object

### Static distance

• distance<Out>(a: Out, b: Out): number
• Calculates the euclidean distance of two vectors

### Static divide

• divide<Out>(out: Out, a: Out, b: Out): Out
• Element-wise vector division and save the results to out vector object

### Static dot

• dot<Out>(a: Out, b: Out): number
• Calculates the dot product of the vector

### Static equals

• equals<Out>(a: Out, b: Out, epsilon?: number): boolean
• Check whether the two given vectors are approximately equivalent

### Static floor

• floor<Out>(out: Out, a: Out): Out
• Element-wise rounds down of the current vector and save the results to the out vector

### Static fromArray

• fromArray<Out>(out: Out, arr: IWritableArrayLike<number>, ofs?: number): Out
• Converts the given array to a vector

#### Parameters

• ##### Default value ofs: number = 0

Array Start Offset

### Static inverse

• inverse<Out>(out: Out, a: Out): Out
• Sets each element to its inverse value, zero value will become Infinity

### Static inverseSafe

• inverseSafe<Out>(out: Out, a: Out): Out
• Sets each element to its inverse value, zero value will remain zero

### Static len

• len<Out>(a: Out): number
• Calculates the length of the vector

### Static lengthSqr

• lengthSqr<Out>(a: Out): number
• Calculates the squared length of the vector

### Static lerp

• lerp<Out>(out: Out, a: Out, b: Out, t: number): Out
• Calculates the linear interpolation between two vectors with a given ratio

### Static max

• max<Out>(out: Out, a: Out, b: Out): Out
• Calculates the maximum values by elements of the vector and save the results to the out vector

### Static min

• min<Out>(out: Out, a: Out, b: Out): Out
• Calculates the minimum values by elements of the vector and save the results to the out vector

### Static multiply

• multiply<Out>(out: Out, a: Out, b: Out): Out
• Element-wise vector multiplication and save the results to out vector object

### Static multiplyScalar

• multiplyScalar<Out>(out: Out, a: Out, b: number): Out
• Vector scalar multiplication and save the results to out vector object

### Static negate

• negate<Out>(out: Out, a: Out): Out
• Sets each element to its negative value

### Static normalize

• normalize<Out>(out: Out, a: Out): Out
• Sets the normalized vector to the out vector

### Static random

• random<Out>(out: Out, scale?: undefined | number): Out
• Generates a uniformly distributed random vector points from center to the surface of the unit sphere

#### Parameters

• ##### Optional scale: undefined | number

vector length

### Static round

• round<Out>(out: Out, a: Out): Out
• Calculates element-wise round results and save to the out vector

#### Returns Out

• scaleAndAdd<Out>(out: Out, a: Out, b: Out, scale: number): Out
• Element-wise multiplication and addition with the equation: a + b * scale

### Static set

• set<Out>(out: Out, x: number, y: number, z: number, w: number): Out
• Sets the out vector with the given x, y, z and w values

### Static squaredDistance

• squaredDistance<Out>(a: Out, b: Out): number
• Calculates the squared euclidean distance of two vectors

### Static strictEquals

• strictEquals<Out>(a: Out, b: Out): boolean
• Check the equality of the two given vectors

### Static subtract

• subtract<Out>(out: Out, a: Out, b: Out): Out
• Element-wise vector subtraction and save the results to out vector object

### Static toArray

• toArray<Out>(out: Out, v: IVec4Like, ofs?: number): Out
• Converts the given vector to an array

#### Parameters

• ##### Default value ofs: number = 0

Array Start Offset

### Static transformAffine

• transformAffine<Out, VecLike, MatLike>(out: Out, v: VecLike, m: MatLike): Out
• Transform the vector with the given affine transformation

### Static transformMat4

• transformMat4<Out, MatLike>(out: Out, a: Out, m: MatLike): Out
• Vector and fourth order matrix multiplication

### Static transformQuat

• transformQuat<Out, QuatLike>(out: Out, a: Out, q: QuatLike): Out
• Vector quaternion multiplication

#### Returns Out

Generated using TypeDoc