---
title: Namespace: vec3
source: https://vjmap.com/doc/Namespace_vec3.html
---

# Namespace: vec3

### Table of contents

#### Type aliases

- [valueType](#valuetype)

#### Functions

- [add](#add)
- [angle](#angle)
- [bezier](#bezier)
- [ceil](#ceil)
- [clone](#clone)
- [copy](#copy)
- [create](#create)
- [cross](#cross)
- [distance](#distance)
- [divide](#divide)
- [dot](#dot)
- [equals](#equals)
- [exactEquals](#exactequals)
- [floor](#floor)
- [forEach](#foreach)
- [fromValues](#fromvalues)
- [hermite](#hermite)
- [inverse](#inverse)
- [length](#length)
- [lerp](#lerp)
- [max](#max)
- [min](#min)
- [multiply](#multiply)
- [negate](#negate)
- [normalize](#normalize)
- [random](#random)
- [rotateX](#rotatex)
- [rotateY](#rotatey)
- [rotateZ](#rotatez)
- [round](#round)
- [scale](#scale)
- [scaleAndAdd](#scaleandadd)
- [set](#set)
- [squaredDistance](#squareddistance)
- [squaredLength](#squaredlength)
- [str](#str)
- [subtract](#subtract)
- [transformMat3](#transformmat3)
- [transformMat4](#transformmat4)
- [transformQuat](#transformquat)

### Type aliases

#### valueType

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

### Functions

#### add

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

Adds two vec3's

##### Parameters

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

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

out

___

#### angle

▸ **angle**(`a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type)): *number*

Get the angle between two 3D vectors

##### Parameters

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

**Returns:** *number*

The angle in radians

___

#### bezier

▸ **bezier**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type), `c`: [*vec3type*](#vec3type), `d`: [*vec3type*](#vec3type), `t`: *number*): [*vec3type*](#vec3type)

Performs a bezier interpolation with two control points

##### Parameters

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

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

out

___

#### ceil

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

Math.ceil the components of a vec3

##### Parameters

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

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

out

___

#### clone

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

Creates a new vec3 initialized with values from an existing vector

##### Parameters

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

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

a new 3D vector

___

#### copy

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

Copy the values from one vec3 to another

##### Parameters

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

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

out

___

#### create

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

Creates a new, empty vec3

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

a new 3D vector

___

#### cross

▸ **cross**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type)): [*vec3type*](#vec3type)

Computes the cross product of two vec3's

##### Parameters

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

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

out

___

#### distance

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

Calculates the euclidian distance between two vec3's

##### Parameters

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

**Returns:** *number*

distance between a and b

___

#### divide

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

Divides two vec3's

##### Parameters

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

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

out

___

#### dot

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

Calculates the dot product of two vec3's

##### Parameters

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

**Returns:** *number*

dot product of a and b

___

#### equals

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

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

##### Parameters

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

**Returns:** *boolean*

True if the vectors are equal, false otherwise.

___

#### exactEquals

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

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

##### Parameters

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

**Returns:** *boolean*

True if the vectors are equal, false otherwise.

___

#### floor

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

Math.floor the components of a vec3

##### Parameters

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

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

out

___

#### forEach

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

Perform some operation over an array of vec3s.

**`function`**

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `a` | [*vec3type*](#vec3type) | the array of vectors to iterate over |
| `stride` | *number* | Number of elements between the start of each vec3. If 0 assumes tightly packed |
| `offset` | *number* | Number of elements to skip at the beginning of the array |
| `count` | *number* | Number of vec3s to iterate over. If 0 iterates over entire array |
| `fn` | (`out`: [*vec3type*](#vec3type), `vec`: [*vec3type*](#vec3type), `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*): [*vec3type*](#vec3type)

Creates a new vec3 initialized with the given values

##### Parameters

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

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

a new 3D vector

___

#### hermite

▸ **hermite**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type), `c`: [*vec3type*](#vec3type), `d`: [*vec3type*](#vec3type), `t`: *number*): [*vec3type*](#vec3type)

Performs a hermite interpolation with two control points

##### Parameters

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

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

out

___

#### inverse

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

Returns the inverse of the components of a vec3

##### Parameters

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

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

out

___

#### length

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

Calculates the length of a vec3

##### Parameters

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

**Returns:** *number*

length of a

___

#### lerp

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

Performs a linear interpolation between two vec3's

##### Parameters

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

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

out

___

#### max

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

Returns the maximum of two vec3's

##### Parameters

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

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

out

___

#### min

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

Returns the minimum of two vec3's

##### Parameters

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

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

out

___

#### multiply

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

Multiplies two vec3's

##### Parameters

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

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

out

___

#### negate

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

Negates the components of a vec3

##### Parameters

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

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

out

___

#### normalize

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

Normalize a vec3

##### Parameters

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

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

out

___

#### random

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

Generates a random vector with the given scale

##### Parameters

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

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

out

___

#### rotateX

▸ **rotateX**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type), `c`: *number*): [*vec3type*](#vec3type)

Rotate a 3D vector around the x-axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec3type*](#vec3type) | The receiving vec3 |
| `a` | [*vec3type*](#vec3type) | The vec3 point to rotate |
| `b` | [*vec3type*](#vec3type) | The origin of the rotation |
| `c` | *number* | The angle of rotation |

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

out

___

#### rotateY

▸ **rotateY**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type), `c`: *number*): [*vec3type*](#vec3type)

Rotate a 3D vector around the y-axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec3type*](#vec3type) | The receiving vec3 |
| `a` | [*vec3type*](#vec3type) | The vec3 point to rotate |
| `b` | [*vec3type*](#vec3type) | The origin of the rotation |
| `c` | *number* | The angle of rotation |

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

out

___

#### rotateZ

▸ **rotateZ**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `b`: [*vec3type*](#vec3type), `c`: *number*): [*vec3type*](#vec3type)

Rotate a 3D vector around the z-axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*vec3type*](#vec3type) | The receiving vec3 |
| `a` | [*vec3type*](#vec3type) | The vec3 point to rotate |
| `b` | [*vec3type*](#vec3type) | The origin of the rotation |
| `c` | *number* | The angle of rotation |

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

out

___

#### round

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

Math.round the components of a vec3

##### Parameters

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

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

out

___

#### scale

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

Scales a vec3 by a scalar number

##### Parameters

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

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

out

___

#### scaleAndAdd

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

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

##### Parameters

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

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

out

___

#### set

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

Set the components of a vec3 to the given values

##### Parameters

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

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

out

___

#### squaredDistance

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

Calculates the squared euclidian distance between two vec3's

##### Parameters

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

**Returns:** *number*

squared distance between a and b

___

#### squaredLength

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

Calculates the squared length of a vec3

##### Parameters

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

**Returns:** *number*

squared length of a

___

#### str

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

Returns a string representation of a vector

##### Parameters

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

**Returns:** *string*

string representation of the vector

___

#### subtract

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

Subtracts vector b from vector a

##### Parameters

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

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

out

___

#### transformMat3

▸ **transformMat3**(`out`: [*vec3type*](#vec3type), `a`: [*vec3type*](#vec3type), `m`: [*mat4type*](#mat4type)): [*vec3type*](#vec3type)

Transforms the vec3 with a mat3.

##### Parameters

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

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

out

___

#### transformMat4

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

Transforms the vec3 with a mat4.
4th vector component is implicitly '1'

##### Parameters

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

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

out

___

#### transformQuat

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

Transforms the vec3 with a quat

##### Parameters

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

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

out


<a name="modulesvec4md"></a>

[vjmap](#readmemd) / [Exports](#modulesmd) / vec4
