Options
All
• Public
• Public/Protected
• All

# Class Vec3

Representation of 3D vectors and points.

## Constructors

### constructor

• newVec3(v: Vec3): Vec3
• newVec3(x?: undefined | number, y?: undefined | number, z?: undefined | number): Vec3

## Properties

x: number

x component.

y: number

y component.

z: number

z component.

### Static FORWARD

FORWARD: {} = Object.freeze(new Vec3(0, 0, -1))

### Static NEGONE

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

### Static ONE

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

### Static RIGHT

RIGHT: {} = Object.freeze(new Vec3(1, 0, 0))

### Static UNITX

UNITX: {} = Object.freeze(new Vec3(1, 0, 0))

### Static UNITY

UNITY: {} = Object.freeze(new Vec3(0, 1, 0))

### Static UNITZ

UNITZ: {} = Object.freeze(new Vec3(0, 0, 1))

### Static UP

UP: {} = Object.freeze(new Vec3(0, 1, 0))

### Static ZERO

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

## Methods

• Adds the current vector with another one and return this

#### Parameters

• ##### other: Vec3

specified vector

#### Returns this

• add3f(x: number, y: number, z: 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

### clampf

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

#### Parameters

• ##### minInclusive: Vec3

Minimum value allowed

• ##### maxInclusive: Vec3

Maximum value allowed

#### Returns this

`this`

### cross

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

#### Parameters

• ##### other: Vec3

specified vector

### divide

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

#### Parameters

• ##### other: Vec3

specified vector

### divide3f

• divide3f(x: number, y: number, z: 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

### dot

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

#### Parameters

• ##### other: Vec3

specified vector

#### Returns number

The result of calculates the dot product with another vector

### equals

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

#### Parameters

• ##### other: Vec3

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`.

### equals3f

• equals3f(x: number, y: number, z: 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

• ##### 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: Vec3, ratio: number): this
• Calculate linear interpolation result between this vector and another one with given ratio.

#### Parameters

• ##### to: Vec3

Target vector

• ##### ratio: number

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

### multiply

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

#### Parameters

• ##### other: Vec3

specified vector

### multiply3f

• multiply3f(x: number, y: number, z: 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

### 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: Vec3): any
• set(x?: undefined | number, y?: undefined | number, z?: undefined | number): any
• Set the current vector value with the given vector.

#### Parameters

• ##### other: Vec3

Specified vector

#### Returns any

`this`

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

x value

y value

z value

#### Returns any

`this`

### strictEquals

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

#### Parameters

• ##### other: Vec3

specified vector

#### Returns boolean

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

### strictEquals3f

• strictEquals3f(x: number, y: number, z: number): boolean
• Check whether the current vector strictly equals another Vec3.

#### 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

#### 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: Vec3): this
• Subtracts one vector from this, and returns this.

#### Parameters

• ##### other: Vec3

specified vector

### subtract3f

• subtract3f(x: number, y: number, z: 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

### toString

• toString(): string

### transformMat4

• transformMat4(matrix: Mat4): this
• Transforms the vec3 with a mat4. 4th vector component is implicitly '1'

#### Parameters

• ##### matrix: Mat4

matrix to transform with

#### Returns this

• Element-wise vector addition and save the results to out vector object

### Static angle

• Calculates the radian angle between two vectors

### Static ceil

• Rounds up by elements of the vector and save the results to out vector object

### Static clone

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

### Static copy

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

### Static cross

• Calculates the cross product of the vector

### Static distance

• Calculates the euclidean distance of two vectors

### Static divide

• Element-wise vector division and save the results to out vector object

### Static dot

• Calculates the dot product of the vector

### Static equals

• Check whether the two given vectors are approximately equivalent

### Static floor

• 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 invert

• Sets each element to its inverse value, zero value will become Infinity

### Static invertSafe

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

### Static len

• Calculates the length of the vector

### Static lengthSqr

• Calculates the squared length of the vector

### Static lerp

• Calculates the linear interpolation between two vectors with a given ratio

### Static max

• Calculates element-wise maximum values and save to the out vector

### Static min

• Calculates element-wise minimum values and save to the out vector

### Static multiply

• Element-wise vector multiplication and save the results to out vector object

### Static multiplyScalar

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

### Static negate

• Sets each element to its negative value

### Static normalize

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

### Static project

• Calculates the projection on the specified vector

#### Parameters

• ##### a: IVec3Like

projection vector

### Static projectOnPlane

• Calculates the projection vector on the specified plane

#### Parameters

• ##### a: IVec3Like

projection vector

• ##### n: IVec3Like

the normal line of specified plane

### 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 rotateX

• Rotates the vector with specified angle around X axis

#### Parameters

• ##### v: IVec3Like

rotation vector

• ##### o: IVec3Like

center of rotation

### Static rotateY

• Rotates the vector with specified angle around Y axis

#### Parameters

• ##### v: IVec3Like

rotation vector

• ##### o: IVec3Like

center of rotation

### Static rotateZ

• Rotates the vector with specified angle around Z axis

#### Parameters

• ##### v: IVec3Like

rotation vector

• ##### o: IVec3Like

center of rotation

### Static round

• Calculates element-wise round results and save to the out vector

#### Returns Out

• Element-wise multiplication and addition with the equation: a + b * scale

### Static set

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

### Static squaredDistance

• Calculates the squared euclidean distance of two vectors

### Static strictEquals

• Check the equality of the two given vectors

### Static subtract

• Element-wise vector subtraction and save the results to out vector object

### Static toArray

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

#### Parameters

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

Array Start Offset

### Static transformAffine

• Affine transformation vector

### Static transformInverseRTS

• Transforms the current vector with given scale, rotation and translation in reverse order

### Static transformMat3

• Vector and third order matrix multiplication

### Static transformMat4

• Vector and fourth order matrix multiplication, will complete the vector with a fourth value as one

### Static transformMat4Normal

• Vector and fourth order matrix multiplication, will complete the vector with a fourth element as one

### Static transformQuat

• Vector quaternion multiplication

### Static transformRTS

• Transforms the current vector with given scale, rotation and translation in order

### Static zero

• zero<Out>(out: Out): Out
• return a Vec3 object with x = 0, y = 0, z = 0.

#### Returns Out

Generated using TypeDoc