Class Quaternion

Implementation of a quaternion. This is used for rotating things without incurring in the dreaded gimbal lock issue, amongst other advantages.

example

var quaternion = new THREE.Quaternion(); quaternion.setFromAxisAngle( new THREE.Vector3( 0, 1, 0 ), Math.PI / 2 ); var vector = new THREE.Vector3( 1, 0, 0 ); vector.applyQuaternion( quaternion );

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(x?: number, y?: number, z?: number, w?: number): Quaternion

Parameters

  • x?: number optional

    x coordinate

  • y?: number optional

    y coordinate

  • z?: number optional

    z coordinate

  • w?: number optional

    w coordinate

Returns

Quaternion

Properties

public w: number

public x: number

public y: number

public z: number

Methods

public clone(): Quaternion

Clones this quaternion.

Returns

Quaternion

public conjugate(): Quaternion

Returns

Quaternion

public copy(q: Quaternion): Quaternion

Copies values of q to this quaternion.

Parameters

Returns

Quaternion

public equals(v: Quaternion): boolean

Parameters

Returns

boolean

public fromArray(n: Array<number>): Quaternion

Parameters

  • n: Array<number>

Returns

Quaternion

public inverse(): Quaternion

Inverts this quaternion.

Returns

Quaternion

public length(): number

Computes length of this quaternion.

Returns

number

public lengthSq(): number

Returns

number

public multiply(q: Quaternion): Quaternion

Multiplies this quaternion by b.

Parameters

Returns

Quaternion

public multiplyQuaternions(a: Quaternion, b: Quaternion): Quaternion

Sets this quaternion to a x b Adapted from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm.

Parameters

Returns

Quaternion

public multiplyVector3(vector: Vector3, dest: Vector3): Quaternion

Parameters

Returns

Quaternion

public normalize(): Quaternion

Normalizes this quaternion.

Returns

Quaternion

public set(x: number, y: number, z: number, w: number): Quaternion

Sets values of this quaternion.

Parameters

  • x: number
  • y: number
  • z: number
  • w: number

Returns

Quaternion

public setFromAxisAngle(axis: Vector3, angle: number): Quaternion

Sets this quaternion from rotation specified by axis and angle. Adapted from http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm. Axis have to be normalized, angle is in radians.

Parameters

Returns

Quaternion

public setFromEuler(euler: Euler, update?: boolean): Quaternion

Parameters

  • euler: Euler
  • update?: boolean optional

Returns

Quaternion

public setFromEuler(v: Vector3, order: string): Quaternion

Sets this quaternion from rotation specified by Euler angles.

Parameters

Returns

Quaternion

public setFromRotationMatrix(m: Matrix4): Quaternion

Sets this quaternion from rotation component of m. Adapted from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm.

Parameters

Returns

Quaternion

public static slerp(qa: Quaternion, qb: Quaternion, qm: Quaternion, t: number): Quaternion

Adapted from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/.

Parameters

Returns

Quaternion

public slerp(qb: Quaternion, t: number): Quaternion

Parameters

Returns

Quaternion

public toArray(): Array<number>

Returns

Array<number>