# B.Math.Quaternion()

Represents a unit quaternion.

To create the object use B.Math.makeQuaternion().

Note: the order of transformations coincides with the order in which the quaternions are multiplied (from left to right).

## CONSTANTS:

IDENTITY = {w: 1.0, x: 0.0, y: 0.0, z: 0.0}

Identity quaternion.

## METHODS:

clone()

Clones this quaternion to a new quaternion object.

### RETURNS:

this

copy(q)

Copies a given quaternion object into this quaternion.

### RETURNS:

this

set(w, x, y, z)

Sets all elements and performs normalization.

{number} w

{number} x

{number} y

{number} z

### RETURNS:

this

get(index)

Gets an element by its index.

{number} index

{number}

### THROWS:

{Error}

if the index is out of range

fromArray(array, offset)

Sets this quaternion from a part of array and performs normalization.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

toArray(array, offset)

Sets this quaternion to a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

fromAxisAngle(axis, angle)

Sets this quaternion from an axis vector and an angle.

axis

{number} angle

### RETURNS:

this

fromRotationMatrix(matrix)

Sets this quaternion from any rotation matrix.

matrix

### RETURNS:

this

fromAngles(angles)

Sets this quaternion from Euler angles.

angles

### RETURNS:

this

axis(result)

Returns the axis vector (or zero-vector for identity quaternion).

### PARAMETERS:

[result]

omit if you want to return newly created vector.

### RETURNS:

angle()

Returns the angle.

### RETURNS:

{number}

mulQuaternions(a, b)

Multiplies two given quaternions and sets the result to this.

### RETURNS:

this

mul(q)

Multiplies this quaternion by a given quaternion.

### RETURNS:

this

dot(q)

Calculates the dot product of this quaternion and another quaternion.

### RETURNS:

{number}

this

invert()

Inverts this quaternion.

### RETURNS:

this

slerp(q, t, result)

Spherically interpolates between this quaternion and another quaternion by t.

### PARAMETERS:

{number} t

[0.0, 1.0]

[result]

omit if you want to return newly created quaternion.

### RETURNS:

this

equal(q)

Checks for strict equality of this quaternion and another quaternion.

{boolean}