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

Get the quaternion conjugate

Parameters:

Returns:

copy

(
  • source
)
Quaternion

Copies value of source to this quaternion.

Parameters:

Returns:

Quaternion:

this

inverse

(
  • target
)
Quaternion

Get the inverse quaternion rotation.

Parameters:

Returns:

mult

(
  • q
  • target
)
Quaternion

Quaternion multiplication

Parameters:

Returns:

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

(
  • 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.

setFromAxisAngle

(
  • axis
  • angle
)

Set the quaternion components given an axis and an angle.

Parameters:

  • axis Vec3
  • angle Number

    in radians

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:

toArray

()

Convert to an Array

Returns:

Array

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

Returns:

string

vmult

(
  • v
  • target
)
Vec3

Multiply the quaternion by a vector

Parameters:

Returns:

Vec3:

Properties

w

Number

The multiplier of the real quaternion basis vector.

x

Number

y

Number

z

Number