# 四元数（[name]）

## 代码示例

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

## 构造函数

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

[page:Float x] - x 坐标
[page:Float y] - y 坐标
[page:Float z] - z 坐标
[page:Float w] - w 坐标

## 方法

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

[page:Quaternion v] - 用于进行比较的四元数。

### [method:Quaternion fromArray]( [param:Array array], [param:Integer offset] )

[page:Array array] - 用于构造四元数的形如(x, y, z, w)的数组。
[page:Integer offset] - （可选）数组的偏移量。（译者注：使用数组中从第offset元素算起的四个元素）

### [method:Quaternion premultiply]( [param:Quaternion q] )

Pre-multiplies this quaternion by [page:Quaternion q].

### [method:Quaternion rotateTowards]( [param:Quaternion q], [param:Float step] )

[page:Quaternion q] - The target quaternion.
[page:Float step] - The angular step in radians.

Rotates this quaternion by a given angular step to the defined quaternion *q*. The method ensures that the final quaternion will not overshoot *q*.

### [method:Quaternion slerp]( [param:Quaternion qb], [param:Float t] )

[page:Quaternion qb] - The other quaternion rotation
[page:Float t] - interpolation factor in the closed interval [0, 1].

Handles the spherical linear interpolation between quaternions. [page:Float t] represents the amount of rotation between this quaternion (where [page:Float t] is 0) and [page:Quaternion qb] (where [page:Float 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 ); ```

### [method:this slerpQuaternions]( [param:Quaternion qa], [param:Quaternion qb], [param:Float t] )

Performs a spherical linear interpolation between the given quaternions and stores the result in this quaternion.

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

Sets this quaternion to the rotation required to rotate direction vector [page:Vector3 vFrom] to direction vector [page:Vector3 vTo].
[page:Vector3 vFrom] and [page:Vector3 vTo] are assumed to be normalized.

### [method:Array toArray]( [param:Array array], [param:Integer offset] )

[page:Array array] - （可选）存储该四元数的数组。若未指定该参数，则将创建一个新数组。
[page:Integer offset] - （可选）若指定了该值，结果将会被拷贝到该 [page:Array]。

### [method:this fromBufferAttribute]( [param:BufferAttribute attribute], [param:Integer index] )

[page:BufferAttribute attribute] - 源 attribute。
[page:Integer index] - attribute 中的索引。

## 静态方法

### [method:null slerpFlat]( [param:Array dst], [param:Integer dstOffset], [param:Array src0], [param:Integer srcOffset0], [param:Array src1], [param:Integer srcOffset1], [param:Float t] )

[page:Array dst] - The output array.
[page:Integer dstOffset] - An offset into the output array.
[page:Array src0] - The source array of the starting quaternion.
[page:Integer srcOffset0] - An offset into the array *src0*.
[page:Array src1] - The source array of the target quatnerion.
[page:Integer srcOffset1] - An offset into the array *src1*.
[page:Float t] - Normalized interpolation factor (between 0 and 1).

Like the static *slerp* method above, but operates directly on flat arrays of numbers.