---
title: Namespace: quat
source: https://vjmap.com/doc/Namespace_quat.html
---

# Namespace: quat

### Table of contents

#### Type aliases

- [valueType](#valuetype)

#### Functions

- [add](#add)
- [calculateW](#calculatew)
- [clone](#clone)
- [conjugate](#conjugate)
- [copy](#copy)
- [create](#create)
- [dot](#dot)
- [equals](#equals)
- [exactEquals](#exactequals)
- [fromMat3](#frommat3)
- [fromValues](#fromvalues)
- [getAxisAngle](#getaxisangle)
- [identity](#identity)
- [invert](#invert)
- [length](#length)
- [lerp](#lerp)
- [multiply](#multiply)
- [normalize](#normalize)
- [rotateX](#rotatex)
- [rotateY](#rotatey)
- [rotateZ](#rotatez)
- [rotationTo](#rotationto)
- [scale](#scale)
- [set](#set)
- [setAxes](#setaxes)
- [setAxisAngle](#setaxisangle)
- [slerp](#slerp)
- [sqlerp](#sqlerp)
- [squaredLength](#squaredlength)
- [str](#str)

### Type aliases

#### valueType

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

### Functions

#### add

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

Adds two quat's

**`function`**

##### Parameters

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

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

out

___

#### calculateW

▸ **calculateW**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype)): [*quattype*](#quattype)

Calculates the W component of a quat from the X, Y, and Z components.
Assumes that quaternion is 1 unit in length.
Any existing W component will be ignored.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |
| `a` | [*quattype*](#quattype) | quat to calculate W component of |

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

out

___

#### clone

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

Creates a new quat initialized with values from an existing quaternion

**`function`**

##### Parameters

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

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

a new quaternion

___

#### conjugate

▸ **conjugate**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype)): [*quattype*](#quattype)

Calculates the conjugate of a quat
If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |
| `a` | [*quattype*](#quattype) | quat to calculate conjugate of |

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

out

___

#### copy

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

Copy the values from one quat to another

**`function`**

##### Parameters

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

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

out

___

#### create

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

Creates a new identity quat

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

a new quaternion

___

#### dot

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

Calculates the dot product of two quat's

**`function`**

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

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

Returns whether or not the quaternions 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

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

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

##### Parameters

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

**Returns:** *boolean*

True if the vectors are equal, false otherwise.

___

#### fromMat3

▸ **fromMat3**(`out`: [*quattype*](#quattype), `m`: [*mat3type*](#mat3type)): [*quattype*](#quattype)

Creates a quaternion from the given 3x3 rotation matrix.

NOTE: The resultant quaternion is not normalized, so you should be sure
to renormalize the quaternion yourself where necessary.

**`function`**

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |
| `m` | [*mat3type*](#mat3type) | rotation matrix |

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

out

___

#### fromValues

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

Creates a new quat initialized with the given values

**`function`**

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

___

#### getAxisAngle

▸ **getAxisAngle**(`outAxis`: [*vec3type*](#vec3type), `q`: [*quattype*](#quattype)): *number*

Gets the rotation axis and angle for a given
 quaternion. If a quaternion is created with
 setAxisAngle, this method will return the same
 values as providied in the original parameter list
 OR functionally equivalent values.
Example: The quaternion formed by axis [0, 0, 1] and
 angle -90 is the same as the quaternion formed by
 [0, 0, 1] and 270. This method favors the latter.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `outAxis` | [*vec3type*](#vec3type) | Vector receiving the axis of rotation |
| `q` | [*quattype*](#quattype) | Quaternion to be decomposed |

**Returns:** *number*

Angle, in radians, of the rotation

___

#### identity

▸ **identity**(`out`: [*quattype*](#quattype)): [*quattype*](#quattype)

Set a quat to the identity quaternion

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |

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

out

___

#### invert

▸ **invert**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype)): [*quattype*](#quattype)

Calculates the inverse of a quat

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |
| `a` | [*quattype*](#quattype) | quat to calculate inverse of |

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

out

___

#### length

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

Calculates the length of a quat

**`function`**

##### Parameters

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

**Returns:** *number*

length of a

___

#### lerp

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

Performs a linear interpolation between two quat's

**`function`**

##### Parameters

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

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

out

___

#### multiply

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

Multiplies two quat's

##### Parameters

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

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

out

___

#### normalize

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

Normalize a quat

**`function`**

##### Parameters

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

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

out

___

#### rotateX

▸ **rotateX**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype), `rad`: *number*): [*quattype*](#quattype)

Rotates a quaternion by the given angle about the X axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | quat receiving operation result |
| `a` | [*quattype*](#quattype) | quat to rotate |
| `rad` | *number* | angle (in radians) to rotate |

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

out

___

#### rotateY

▸ **rotateY**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype), `rad`: *number*): [*quattype*](#quattype)

Rotates a quaternion by the given angle about the Y axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | quat receiving operation result |
| `a` | [*quattype*](#quattype) | quat to rotate |
| `rad` | *number* | angle (in radians) to rotate |

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

out

___

#### rotateZ

▸ **rotateZ**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype), `rad`: *number*): [*quattype*](#quattype)

Rotates a quaternion by the given angle about the Z axis

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | quat receiving operation result |
| `a` | [*quattype*](#quattype) | quat to rotate |
| `rad` | *number* | angle (in radians) to rotate |

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

out

___

#### rotationTo

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

Sets a quaternion to represent the shortest rotation from one
vector to another.

Both vectors are assumed to be unit length.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion. |
| `a` | [*vec3type*](#vec3type) | the initial vector |
| `b` | [*vec3type*](#vec3type) | the destination vector |

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

out

___

#### scale

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

Scales a quat by a scalar number

**`function`**

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

___

#### set

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

Set the components of a quat to the given values

**`function`**

##### Parameters

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

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

out

___

#### setAxes

▸ **setAxes**(`out`: [*quattype*](#quattype), `view`: [*vec3type*](#vec3type), `right`: [*vec3type*](#vec3type), `up`: [*vec3type*](#vec3type)): [*quattype*](#quattype)

Sets the specified quaternion with values corresponding to the given
axes. Each axis is a vec3 and is expected to be unit length and
perpendicular to all other specified axes.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | - |
| `view` | [*vec3type*](#vec3type) | the vector representing the viewing direction |
| `right` | [*vec3type*](#vec3type) | the vector representing the local "right" direction |
| `up` | [*vec3type*](#vec3type) | the vector representing the local "up" direction |

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

out

___

#### setAxisAngle

▸ **setAxisAngle**(`out`: [*quattype*](#quattype), `axis`: [*vec3type*](#vec3type), `rad`: *number*): [*quattype*](#quattype)

Sets a quat from the given angle and rotation axis,
then returns it.

##### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `out` | [*quattype*](#quattype) | the receiving quaternion |
| `axis` | [*vec3type*](#vec3type) | the axis around which to rotate |
| `rad` | *number* | the angle in radians |

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

out

___

#### slerp

▸ **slerp**(`out`: [*quattype*](#quattype), `a`: [*quattype*](#quattype), `b`: [*quattype*](#quattype), `t`: *number*): [*quattype*](#quattype)

Performs a spherical linear interpolation between two quat

##### Parameters

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

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

out

___

#### sqlerp

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

Performs a spherical linear interpolation with two control points

##### Parameters

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

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

out

___

#### squaredLength

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

Calculates the squared length of a quat

**`function`**

##### Parameters

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

**Returns:** *number*

squared length of a

___

#### str

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

Returns a string representation of a quatenion

##### Parameters

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

**Returns:** *string*

string representation of the vector


<a name="modulesspringmd"></a>

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