---
title: Namespace: vec4
source: https://vjmap.com/doc/Namespace_vec4.html
---

# Namespace: vec4

### Table of contents

#### Type aliases

- [valueType](#valuetype)

#### Functions

- [add](#add)
- [ceil](#ceil)
- [clone](#clone)
- [copy](#copy)
- [create](#create)
- [distance](#distance)
- [divide](#divide)
- [dot](#dot)
- [equals](#equals)
- [exactEquals](#exactequals)
- [floor](#floor)
- [forEach](#foreach)
- [fromValues](#fromvalues)
- [inverse](#inverse)
- [length](#length)
- [lerp](#lerp)
- [max](#max)
- [min](#min)
- [multiply](#multiply)
- [negate](#negate)
- [normalize](#normalize)
- [random](#random)
- [round](#round)
- [scale](#scale)
- [scaleAndAdd](#scaleandadd)
- [set](#set)
- [squaredDistance](#squareddistance)
- [squaredLength](#squaredlength)
- [str](#str)
- [subtract](#subtract)
- [transformMat4](#transformmat4)
- [transformQuat](#transformquat)

### Type aliases

#### valueType

Ƭ **valueType**: [*vec4type*](#vec4type)

### Functions

#### add

▸ **add**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Adds two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### ceil

▸ **ceil**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Math.ceil the components of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to ceil |

**Returns:** [*vec4type*](#vec4type)

out

___

#### clone

▸ **clone**(`a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Creates a new vec4 initialized with values from an existing vector

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | vector to clone |

**Returns:** [*vec4type*](#vec4type)

a new 4D vector

___

#### copy

▸ **copy**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Copy the values from one vec4 to another

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the source vector |

**Returns:** [*vec4type*](#vec4type)

out

___

#### create

▸ **create**(): [*vec4type*](#vec4type)

Creates a new, empty vec4

**Returns:** [*vec4type*](#vec4type)

a new 4D vector

___

#### distance

▸ **distance**(`a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): *number*

Calculates the euclidian distance between two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** *number*

distance between a and b

___

#### divide

▸ **divide**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Divides two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### dot

▸ **dot**(`a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): *number*

Calculates the dot product of two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** *number*

dot product of a and b

___

#### equals

▸ **equals**(`a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): *boolean*

Returns whether or not the vectors have approximately the same elements in the same position.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | The first vector. |
| `b` | [*vec4type*](#vec4type) | The second vector. |

**Returns:** *boolean*

True if the vectors are equal, false otherwise.

___

#### exactEquals

▸ **exactEquals**(`a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): *boolean*

Returns whether or not the vectors have exactly the same elements in the same position (when compared with ===)

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | The first vector. |
| `b` | [*vec4type*](#vec4type) | The second vector. |

**Returns:** *boolean*

True if the vectors are equal, false otherwise.

___

#### floor

▸ **floor**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Math.floor the components of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to floor |

**Returns:** [*vec4type*](#vec4type)

out

___

#### forEach

▸ **forEach**(`a`: [*vec4type*](#vec4type), `stride`: *number*, `offset`: *number*, `count`: *number*, `fn`: (`out`: [*vec4type*](#vec4type), `vec`: [*vec4type*](#vec4type), `arg`: *any*) => *void*, `arg?`: *any*): *any*

Perform some operation over an array of vec4s.

**`function`**

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | the array of vectors to iterate over |
| `stride` | *number* | Number of elements between the start of each vec4. If 0 assumes tightly packed |
| `offset` | *number* | Number of elements to skip at the beginning of the array |
| `count` | *number* | Number of vec4s to iterate over. If 0 iterates over entire array |
| `fn` | (`out`: [*vec4type*](#vec4type), `vec`: [*vec4type*](#vec4type), `arg`: *any*) => *void* | Function to call for each vector in the array |
| `arg?` | *any* | - |

**Returns:** *any*

a

___

#### fromValues

▸ **fromValues**(`x`: *number*, `y`: *number*, `z`: *number*, `w`: *number*): [*vec4type*](#vec4type)

Creates a new vec4 initialized with the given values

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `x` | *number* | X component |
| `y` | *number* | Y component |
| `z` | *number* | Z component |
| `w` | *number* | W component |

**Returns:** [*vec4type*](#vec4type)

a new 4D vector

___

#### inverse

▸ **inverse**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Returns the inverse of the components of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to invert |

**Returns:** [*vec4type*](#vec4type)

out

___

#### length

▸ **length**(`a`: [*vec4type*](#vec4type)): *number*

Calculates the length of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | vector to calculate length of |

**Returns:** *number*

length of a

___

#### lerp

▸ **lerp**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type), `t`: *number*): [*vec4type*](#vec4type)

Performs a linear interpolation between two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |
| `t` | *number* | interpolation amount between the two inputs |

**Returns:** [*vec4type*](#vec4type)

out

___

#### max

▸ **max**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Returns the maximum of two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### min

▸ **min**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Returns the minimum of two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### multiply

▸ **multiply**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Multiplies two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### negate

▸ **negate**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Negates the components of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to negate |

**Returns:** [*vec4type*](#vec4type)

out

___

#### normalize

▸ **normalize**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Normalize a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to normalize |

**Returns:** [*vec4type*](#vec4type)

out

___

#### random

▸ **random**(`out`: [*vec4type*](#vec4type), `s?`: *number*): [*vec4type*](#vec4type)

Generates a random vector with the given scale

##### Parameters

| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | - | the receiving vector |
| `s` | *number* | 1.0 | - |

**Returns:** [*vec4type*](#vec4type)

out

___

#### round

▸ **round**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Math.round the components of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | vector to round |

**Returns:** [*vec4type*](#vec4type)

out

___

#### scale

▸ **scale**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: *number*): [*vec4type*](#vec4type)

Scales a vec4 by a scalar number

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the vector to scale |
| `b` | *number* | amount to scale the vector by |

**Returns:** [*vec4type*](#vec4type)

out

___

#### scaleAndAdd

▸ **scaleAndAdd**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type), `s`: *number*): [*vec4type*](#vec4type)

Adds two vec4's after scaling the second operand by a scalar value

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |
| `s` | *number* | the amount to scale b by before adding |

**Returns:** [*vec4type*](#vec4type)

out

___

#### set

▸ **set**(`out`: [*vec4type*](#vec4type), `x`: *number*, `y`: *number*, `z`: *number*, `w`: *number*): [*vec4type*](#vec4type)

Set the components of a vec4 to the given values

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `x` | *number* | X component |
| `y` | *number* | Y component |
| `z` | *number* | Z component |
| `w` | *number* | W component |

**Returns:** [*vec4type*](#vec4type)

out

___

#### squaredDistance

▸ **squaredDistance**(`a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): *number*

Calculates the squared euclidian distance between two vec4's

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** *number*

squared distance between a and b

___

#### squaredLength

▸ **squaredLength**(`a`: [*vec4type*](#vec4type)): *number*

Calculates the squared length of a vec4

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | vector to calculate squared length of |

**Returns:** *number*

squared length of a

___

#### str

▸ **str**(`a`: [*vec4type*](#vec4type)): *string*

Returns a string representation of a vector

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec4type*](#vec4type) | vector to represent as a string |

**Returns:** *string*

string representation of the vector

___

#### subtract

▸ **subtract**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `b`: [*vec4type*](#vec4type)): [*vec4type*](#vec4type)

Subtracts vector b from vector a

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the first operand |
| `b` | [*vec4type*](#vec4type) | the second operand |

**Returns:** [*vec4type*](#vec4type)

out

___

#### transformMat4

▸ **transformMat4**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `m`: [*mat4type*](#mat4type)): [*vec4type*](#vec4type)

Transforms the vec4 with a mat4.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the vector to transform |
| `m` | [*mat4type*](#mat4type) | matrix to transform with |

**Returns:** [*vec4type*](#vec4type)

out

___

#### transformQuat

▸ **transformQuat**(`out`: [*vec4type*](#vec4type), `a`: [*vec4type*](#vec4type), `q`: [*quattype*](#quattype)): [*vec4type*](#vec4type)

Transforms the vec4 with a quat

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec4type*](#vec4type) | the receiving vector |
| `a` | [*vec4type*](#vec4type) | the vector to transform |
| `q` | [*quattype*](#quattype) | quaternion to transform with |

**Returns:** [*vec4type*](#vec4type)

out
