#

API Docs for: 0.6.1
Show: Inherited Protected Private Deprecated

# Quaternion Class

Defined in: `src/math/Quaternion.js:5`

A Quaternion describes a rotation in 3D space. The Quaternion is mathematically defined as Q = xi + yj + z*k + w, where (i,j,k) are imaginary basis vectors. (x,y,z) can be seen as a vector related to the axis of rotation, while the real multiplier, w, is related to the amount of rotation.

## Constructor

### `Quaternion`

(

- `x`
- `y`
- `z`
- `w`

)

Defined in `src/math/Quaternion.js:5`

#### Parameters:

- `x` Number

  Multiplier of the imaginary basis vector i.

- `y` Number

  Multiplier of the imaginary basis vector j.

- `z` Number

  Multiplier of the imaginary basis vector k.

- `w` Number

  Multiplier of the real part.

- Index
- Methods
- Properties

## Item Index

### Methods

- conjugate
- copy
- inverse
- mult
- normalize
- normalizeFast
- set
- setFromAxisAngle
- setFromEuler
- setFromVectors
- toArray
- toAxisAngle
- toEuler
- toString
- vmult

### Properties

- w
- x
- y
- z

## Methods

### `conjugate`

(

- `target`

)
Quaternion

Defined in `src/math/Quaternion.js:184`

Get the quaternion conjugate

#### Parameters:

- `target` Quaternion

#### Returns:

Quaternion:

### `copy`

(

- `source`

)
Quaternion

Defined in `src/math/Quaternion.js:274`

Copies value of source to this quaternion.

#### Parameters:

- `source` Quaternion

#### Returns:

Quaternion:

this

### `inverse`

(

- `target`

)
Quaternion

Defined in `src/math/Quaternion.js:164`

Get the inverse quaternion rotation.

#### Parameters:

- `target` Quaternion

#### Returns:

Quaternion:

### `mult`

(

- `q`
- `target`

)
Quaternion

Defined in `src/math/Quaternion.js:135`

Quaternion multiplication

#### Parameters:

- `q` Quaternion
- `target` Quaternion

  Optional.

#### Returns:

Quaternion:

### `normalize`

()

Defined in `src/math/Quaternion.js:201`

Normalize the quaternion. Note that this changes the values of the quaternion.

### `normalizeFast`

()

Defined in `src/math/Quaternion.js:221`

Approximation of quaternion normalization. Works best when quat is already almost-normalized.

### `set`

(

- `x`
- `y`
- `z`
- `w`

)

Defined in `src/math/Quaternion.js:38`

Set the value of the quaternion.

#### Parameters:

- `x` Number
- `y` Number
- `z` Number
- `w` Number

### `setFromAxisAngle`

(

- `axis`
- `angle`

)

Defined in `src/math/Quaternion.js:71`

Set the quaternion components given an axis and an angle.

#### Parameters:

- `axis` Vec3
- `angle` Number

  in radians

### `setFromEuler`

(

- `x`
- `y`
- `z`
- `order`

)

Defined in `src/math/Quaternion.js:331`

See http://www.mathworks.com/matlabcentral/fileexchange/20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/content/SpinCalc.m

#### Parameters:

- `x` Number
- `y` Number
- `z` Number
- `order` String

  The order to apply angles: 'XYZ' or 'YXZ' or any other combination

### `setFromVectors`

(

- `u`
- `v`

)

Defined in `src/math/Quaternion.js:112`

Set the quaternion value given two vectors. The resulting rotation will be the needed rotation to rotate u to v.

#### Parameters:

- `u` Vec3
- `v` Vec3

### `toArray`

()

Defined in `src/math/Quaternion.js:62`

Convert to an Array

#### Returns:

Array

### `toAxisAngle`

(

- `targetAxis`

)

Defined in `src/math/Quaternion.js:85`

Converts the quaternion to axis/angle representation.

#### Parameters:

- `targetAxis` Vec3

  Optional. A vector object to reuse for storing the axis.

#### Returns:

Array An array, first elemnt is the axis and the second is the angle in radians.

### `toEuler`

(

- `target`
- `string`

)

Defined in `src/math/Quaternion.js:288`

Convert the quaternion to euler angle representation. Order: YZX, as this page describes: http://www.euclideanspace.com/maths/standards/index.htm

#### Parameters:

- `target` Vec3
- `string` Object

  order Three-character string e.g. "YZX", which also is default.

### `toString`

()

Defined in `src/math/Quaternion.js:53`

Convert to a readable format

#### Returns:

string

### `vmult`

(

- `v`
- `target`

)
Vec3

Defined in `src/math/Quaternion.js:242`

Multiply the quaternion by a vector

#### Parameters:

- `v` Vec3
- `target` Vec3

  Optional

#### Returns:

Vec3:

## Properties

### `w`

Number

Defined in `src/math/Quaternion.js:31`

The multiplier of the real quaternion basis vector.

### `x`

Number

Defined in `src/math/Quaternion.js:16`

### `y`

Number

Defined in `src/math/Quaternion.js:21`

### `z`

Number

Defined in `src/math/Quaternion.js:26`