API Docs for: 0.6.1
Show:

# Quaternion Class

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

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

## Methods

### `conjugate`

(
• `target`
)

Get the quaternion conjugate

### `copy`

(
• `source`
)

Copies value of source to this quaternion.

Quaternion:

this

### `inverse`

(
• `target`
)

Get the inverse quaternion rotation.

### `mult`

(
• `q`
• `target`
)

Quaternion multiplication

### `normalize`

()

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

### `normalizeFast`

()

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

### `set`

(
• `x`
• `y`
• `z`
• `w`
)

Set the value of the quaternion.

#### Parameters:

• `x` Number
• `y` Number
• `z` Number
• `w` Number

### `setFromAxisAngle`

(
• `axis`
• `angle`
)

Set the quaternion components given an axis and an angle.

#### Parameters:

• `axis` Vec3
• `angle` Number

### `setFromEuler`

(
• `x`
• `y`
• `z`
• `order`
)

#### Parameters:

• `x` Number
• `y` Number
• `z` Number
• `order` String

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

### `setFromVectors`

(
• `u`
• `v`
)

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`

()

Convert to an Array

Array

### `toAxisAngle`

(
• `targetAxis`
)

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

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`

()

Convert to a readable format

string

### `vmult`

(
• `v`
• `target`
)

Multiply the quaternion by a vector

#### Parameters:

• `v` Vec3
• `target` Vec3

Optional

Vec3:

## Properties

### `w`

Number

The multiplier of the real quaternion basis vector.

Number

Number

Number