# [name]

Implementation of a quaternion. This is used for rotating things without encountering 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 );`

## Constructor

### [name]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )

x - x coordinate
y - y coordinate
z - z coordinate
w - w coordinate

## Properties

### [property:Float x]

### [property:Float y]

### [property:Float z]

### [property:Float w]

## Methods

### [method:Quaternion set]( [page:Float x], [page:Float y], [page:Float z], [page:Float w] )

Sets values of this quaternion.

### [method:Quaternion copy]( [page:Quaternion q] )

Copies values of *q* to this quaternion.

### [method:Quaternion setFromEuler]( [page:Euler euler] )

Sets this quaternion from rotation specified by Euler angle.

### [method:Quaternion setFromAxisAngle]( [page:Vector3 axis], [page:Float angle] )

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

### [method:Quaternion setFromRotationMatrix]( [page:Matrix4 m] )

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

### [method:Quaternion setFromUnitVectors]( [page:Vector3 vFrom], [page:Vector3 vTo] )

Sets this quaternion to the rotation required to rotate direction vector *vFrom* to direction vector *vTo*.
Adapted from [link:http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors].
*vFrom* and *vTo* are assumed to be normalized.

### [method:Quaternion inverse]()

Inverts this quaternion.

### [method:Float length]()

Computes length of this quaternion.

### [method:Quaternion normalize]()

Normalizes this quaternion.

### [method:Quaternion multiply]( [page:Quaternion b] )

Multiplies this quaternion by *b*.

### [method:Quaternion multiplyQuaternions]( [page:Quaternion a], [page:Quaternion b] )

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

### [method:Quaternion multiplyVector3]( [page:Vector3 vector], [page:Vector3 dest] )

Rotates *vector* by this quaternion into *dest*.
If *dest* is not specified, result goes to *vec*.

### [method:Quaternion clone]()

Clones this quaternion.

### [method:Array toArray]( [page:Array array] )

array -- Array to store the quaternion.
Returns the numerical elements of this quaternion in an array of format (x, y, z, w).

### [method:Boolean equals]([page:Quaternion v])

v -- Quaternion that this quaternion will be compared to.
Compares each component of *v* to each component of this quaternion to determine if they represent the same rotation.

### [method:Float lengthSq]()

Calculates the squared length of the quaternion.

### [method:Quaternion fromArray]([page:Array array])

array -- Array of format (x, y, z, w) used to construct the quaternion.
Sets this quaternion's component values from an array.

### [method:Quaternion conjugate]()

Returns the rotational conjugate of this quaternion. The conjugate of a quaternion represents the same rotation in the opposite direction about the rotational axis.

### [method:Quaternion slerp]([page:Quaternion quaternionB], [page:float t])

quaternionB -- The other quaternion rotation
t -- Normalized 0 to 1 interpolation factor
Handles the spherical linear interpolation between quaternions. *t* represents the amount of rotation between this quaternion (where *t* is 0) and quaternionB (where *t* is 1). This quaternion is set to the result. Also see the static version of the *slerp* below.
`// rotate a mesh towards a target quaternion mesh.quaternion.slerp( endQuaternion, 0.01 );`

## Static Methods

### [method:Quaternion slerp]( [page:Quaternion qStart], [page:Quaternion qEnd], [page:Quaternion qTarget], [page:Float t] )

qStart -- The starting quaternion (where *t* is 0)
qEnd -- The ending quaternion (where *t* is 1)
qTarget -- The target quaternion that gets set with the result
t -- Normalized 0 to 1 interpolation factor
Unlike the normal method, the static version of slerp sets a target quaternion to the result of the slerp operation.
`// Code setup var startQuaternion = new THREE.Quaternion().set( 0, 0, 0, 1 ).normalize(); var endQuaternion = new THREE.Quaternion().set( 1, 1, 1, 1 ).normalize(); var t = 0;` `// Update a mesh's rotation in the loop t = ( t + 0.01 ) % 1; // constant angular momentum THREE.Quaternion.slerp( startQuaternion, endQuaternion, mesh.quaternion, t );`

## Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]