# Quaternion

#### new Cesium.Quaternion(x, y, z, w)
Core/Quaternion.js 21

A set of 4-dimensional coordinates used to represent rotation in 3-dimensional space.

Name | Type | Default | Description
--- | --- | --- | ---
`x` | Number | `0.0` | optional The X component.
`y` | Number | `0.0` | optional The Y component.
`z` | Number | `0.0` | optional The Z component.
`w` | Number | `0.0` | optional The W component.

##### See:

- PackableForInterpolation

### Members

#### static constant Cesium.Quaternion.IDENTITY : Quaternion
Core/Quaternion.js 971

An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 1.0).

#### static Cesium.Quaternion.packedInterpolationLength : Number
Core/Quaternion.js 252

The number of elements used to store the object into an array in its interpolatable form.

#### static Cesium.Quaternion.packedLength : Number
Core/Quaternion.js 196

The number of elements used to pack the object into an array.

#### static constant Cesium.Quaternion.ZERO : Quaternion
Core/Quaternion.js 963

An immutable Quaternion instance initialized to (0.0, 0.0, 0.0, 0.0).

#### w : Number
Core/Quaternion.js 48

The W component.

Default Value: `0.0`

#### x : Number
Core/Quaternion.js 27

The X component.

Default Value: `0.0`

#### y : Number
Core/Quaternion.js 34

The Y component.

Default Value: `0.0`

#### z : Number
Core/Quaternion.js 41

The Z component.

Default Value: `0.0`

### Methods

#### static Cesium.Quaternion.add(left, right, result) → Quaternion
Core/Quaternion.js 432

Computes the componentwise sum of two quaternions.

Name | Type | Description
--- | --- | ---
`left` | Quaternion | The first quaternion.
`right` | Quaternion | The second quaternion.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.clone(quaternion, result) → Quaternion
Core/Quaternion.js 322

Duplicates a Quaternion instance.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to duplicate.
`result` | Quaternion | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided. (Returns undefined if quaternion is undefined)

#### static Cesium.Quaternion.computeAngle(quaternion) → Number
Core/Quaternion.js 618

Computes the angle of rotation of the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to use.

##### Returns:

The angle of rotation.

#### static Cesium.Quaternion.computeAxis(quaternion, result) → Cartesian3
Core/Quaternion.js 592

Computes the axis of rotation of the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to use.
`result` | Cartesian3 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.computeInnerQuadrangle(q0, q1, q2, result) → Quaternion
Core/Quaternion.js 765

Computes an inner quadrangle point.

This will compute quaternions that ensure a squad curve is C1.

Name | Type | Description
--- | --- | ---
`q0` | Quaternion | The first quaternion.
`q1` | Quaternion | The second quaternion.
`q2` | Quaternion | The third quaternion.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

##### See:

- Quaternion#squad

#### static Cesium.Quaternion.conjugate(quaternion, result) → Quaternion
Core/Quaternion.js 345

Computes the conjugate of the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to conjugate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.convertPackedArrayForInterpolation(packedArray, startingIndex, lastIndex, result)
Core/Quaternion.js 262

Converts a packed array into a form suitable for interpolation.

Name | Type | Default | Description
--- | --- | --- | ---
`packedArray` | Array.<Number> |  | The packed array.
`startingIndex` | Number | `0` | optional The index of the first element to be converted.
`lastIndex` | Number | `packedArray.length` | optional The index of the last element to be converted.
`result` | Array.<Number> |  | optional The object into which to store the result.

#### static Cesium.Quaternion.divideByScalar(quaternion, scalar, result) → Quaternion
Core/Quaternion.js 571

Divides the provided quaternion componentwise by the provided scalar.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to be divided.
`scalar` | Number | The scalar to divide by.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.dot(left, right) → Number
Core/Quaternion.js 495

Computes the dot (scalar) product of two quaternions.

Name | Type | Description
--- | --- | ---
`left` | Quaternion | The first quaternion.
`right` | Quaternion | The second quaternion.

##### Returns:

The dot product.

#### static Cesium.Quaternion.equals(left, right) → Boolean
Core/Quaternion.js 929

Compares the provided quaternions componentwise and returns `true` if they are equal, `false` otherwise.

Name | Type | Description
--- | --- | ---
`left` | Quaternion | optional The first quaternion.
`right` | Quaternion | optional The second quaternion.

##### Returns:

`true` if left and right are equal, `false` otherwise.

#### static Cesium.Quaternion.equalsEpsilon(left, right, epsilon) → Boolean
Core/Quaternion.js 943

Compares the provided quaternions componentwise and returns `true` if they are within the provided epsilon, `false` otherwise.

Name | Type | Default | Description
--- | --- | --- | ---
`left` | Quaternion |  | optional The first quaternion.
`right` | Quaternion |  | optional The second quaternion.
`epsilon` | Number | `0` | optional The epsilon to use for equality testing.

##### Returns:

`true` if left and right are within the provided epsilon, `false` otherwise.

#### static Cesium.Quaternion.exp(cartesian, result) → Quaternion
Core/Quaternion.js 727

The exponential quaternion function.

Name | Type | Description
--- | --- | ---
`cartesian` | Cartesian3 | The cartesian.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.fastSlerp(start, end, t, result) → Quaternion
Core/Quaternion.js 856

Computes the spherical linear interpolation or extrapolation at t using the provided quaternions. This implementation is faster than `Quaternion#slerp`, but is only accurate up to 10-6.

Name | Type | Description
--- | --- | ---
`start` | Quaternion | The value corresponding to t at 0.0.
`end` | Quaternion | The value corresponding to t at 1.0.
`t` | Number | The point along t at which to interpolate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

##### See:

- Quaternion#slerp

#### static Cesium.Quaternion.fastSquad(q0, q1, s0, s1, t, result) → Quaternion
Core/Quaternion.js 906

Computes the spherical quadrangle interpolation between quaternions. An implementation that is faster than `Quaternion#squad`, but less accurate.

Name | Type | Description
--- | --- | ---
`q0` | Quaternion | The first quaternion.
`q1` | Quaternion | The second quaternion.
`s0` | Quaternion | The first inner quadrangle.
`s1` | Quaternion | The second inner quadrangle.
`t` | Number | The time in [0,1] used to interpolate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter or a new instance if none was provided.

##### See:

- Quaternion#squad

#### static Cesium.Quaternion.fromAxisAngle(axis, angle, result) → Quaternion
Core/Quaternion.js 62

Computes a quaternion representing a rotation around an axis. 生成一个表示旋转角（绕X、Y或Z轴）的四元数

Name | Type | Description
--- | --- | ---
`axis` | Cartesian3 | The axis of rotation.
`angle` | Number | The angle in radians to rotate around the axis.
`result` | Quaternion | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided.

#### static Cesium.Quaternion.fromHeadingPitchRoll(headingPitchRoll, result) → Quaternion
Core/Quaternion.js 174

Computes a rotation from the given heading, pitch and roll angles. Heading is the rotation about the negative z axis. Pitch is the rotation about the negative y axis. Roll is the rotation about the positive x axis.

Name | Type | Description
--- | --- | ---
`headingPitchRoll` | HeadingPitchRoll | The rotation expressed as a heading, pitch and roll.
`result` | Quaternion | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if none was provided.

#### static Cesium.Quaternion.fromRotationMatrix(matrix, result) → Quaternion
Core/Quaternion.js 97

Computes a Quaternion from the provided Matrix3 instance.

Name | Type | Description
--- | --- | ---
`matrix` | Matrix3 | The rotation matrix.
`result` | Quaternion | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided.

##### See:

- Matrix3.fromQuaternion

#### static Cesium.Quaternion.inverse(quaternion, result) → Quaternion
Core/Quaternion.js 414

Computes the inverse of the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to normalize.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.lerp(start, end, t, result) → Quaternion
Core/Quaternion.js 639

Computes the linear interpolation or extrapolation at t using the provided quaternions.

Name | Type | Description
--- | --- | ---
`start` | Quaternion | The value corresponding to t at 0.0.
`end` | Quaternion | The value corresponding to t at 1.0.
`t` | Number | The point along t at which to interpolate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.log(quaternion, result) → Cartesian3
Core/Quaternion.js 704

The logarithmic quaternion function.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The unit quaternion.
`result` | Cartesian3 | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.magnitude(quaternion) → Number
Core/Quaternion.js 378

Computes magnitude for the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to conjugate.

##### Returns:

The magnitude.

#### static Cesium.Quaternion.magnitudeSquared(quaternion) → Number
Core/Quaternion.js 364

Computes magnitude squared for the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to conjugate.

##### Returns:

The magnitude squared.

#### static Cesium.Quaternion.multiply(left, right, result) → Quaternion
Core/Quaternion.js 512

Computes the product of two quaternions.

Name | Type | Description
--- | --- | ---
`left` | Quaternion | The first quaternion.
`right` | Quaternion | The second quaternion.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.multiplyByScalar(quaternion, scalar, result) → Quaternion
Core/Quaternion.js 549

Multiplies the provided quaternion componentwise by the provided scalar.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to be scaled.
`scalar` | Number | The scalar to multiply with.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.negate(quaternion, result) → Quaternion
Core/Quaternion.js 475

Negates the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to be negated.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.normalize(quaternion, result) → Quaternion
Core/Quaternion.js 389

Computes the normalized form of the provided quaternion.

Name | Type | Description
--- | --- | ---
`quaternion` | Quaternion | The quaternion to normalize.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.pack(value, array, startingIndex) → Array.<Number>
Core/Quaternion.js 207

Stores the provided instance into the provided array.

Name | Type | Default | Description
--- | --- | --- | ---
`value` | Quaternion |  | The value to pack.
`array` | Array.<Number> |  | The array to pack into.
`startingIndex` | Number | `0` | optional The index into the array at which to start packing the elements.

##### Returns:

The array that was packed into

#### static Cesium.Quaternion.slerp(start, end, t, result) → Quaternion
Core/Quaternion.js 666

Computes the spherical linear interpolation or extrapolation at t using the provided quaternions.

Name | Type | Description
--- | --- | ---
`start` | Quaternion | The value corresponding to t at 0.0.
`end` | Quaternion | The value corresponding to t at 1.0.
`t` | Number | The point along t at which to interpolate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

##### See:

- Quaternion#fastSlerp

#### static Cesium.Quaternion.squad(q0, q1, s0, s1, t, result) → Quaternion
Core/Quaternion.js 812

Computes the spherical quadrangle interpolation between quaternions.

Name | Type | Description
--- | --- | ---
`q0` | Quaternion | The first quaternion.
`q1` | Quaternion | The second quaternion.
`s0` | Quaternion | The first inner quadrangle.
`s1` | Quaternion | The second inner quadrangle.
`t` | Number | The time in [0,1] used to interpolate.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

##### Example:

    // 1. compute the squad interpolation between two quaternions on a curve
    var s0 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new Cesium.Quaternion());
    var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new Cesium.Quaternion());
    var q = Cesium.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new Cesium.Quaternion());

    // 2. compute the squad interpolation as above but where the first quaternion is a end point.
    var s1 = Cesium.Quaternion.computeInnerQuadrangle(quaternions[0], quaternions[1], quaternions[2], new Cesium.Quaternion());
    var q = Cesium.Quaternion.squad(quaternions[0], quaternions[1], quaternions[0], s1, t, new Cesium.Quaternion());

##### See:

- Quaternion#computeInnerQuadrangle

#### static Cesium.Quaternion.subtract(left, right, result) → Quaternion
Core/Quaternion.js 454

Computes the componentwise difference of two quaternions.

Name | Type | Description
--- | --- | ---
`left` | Quaternion | The first quaternion.
`right` | Quaternion | The second quaternion.
`result` | Quaternion | The object onto which to store the result.

##### Returns:

The modified result parameter.

#### static Cesium.Quaternion.unpack(array, startingIndex, result) → Quaternion
Core/Quaternion.js 231

Retrieves an instance from a packed array.

Name | Type | Default | Description
--- | --- | --- | ---
`array` | Array.<Number> |  | The packed array.
`startingIndex` | Number | `0` | optional The starting index of the element to be unpacked.
`result` | Quaternion |  | optional The object into which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided.

#### static Cesium.Quaternion.unpackInterpolationResult(array, sourceArray, firstIndex, lastIndex, result) → Quaternion
Core/Quaternion.js 297

Retrieves an instance from a packed array converted with `convertPackedArrayForInterpolation`.

Name | Type | Default | Description
--- | --- | --- | ---
`array` | Array.<Number> |  | The array previously packed for interpolation.
`sourceArray` | Array.<Number> |  | The original packed array.
`firstIndex` | Number | `0` | optional The firstIndex used to convert the array.
`lastIndex` | Number | `packedArray.length` | optional The lastIndex used to convert the array.
`result` | Quaternion |  | optional The object into which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided.

#### clone(result) → Quaternion
Core/Quaternion.js 979

Duplicates this Quaternion instance.

Name | Type | Description
--- | --- | ---
`result` | Quaternion | optional The object onto which to store the result.

##### Returns:

The modified result parameter or a new Quaternion instance if one was not provided.

#### equals(right) → Boolean
Core/Quaternion.js 990

Compares this and the provided quaternion componentwise and returns `true` if they are equal, `false` otherwise.

Name | Type | Description
--- | --- | ---
`right` | Quaternion | optional The right hand side quaternion.

##### Returns:

`true` if left and right are equal, `false` otherwise.

#### equalsEpsilon(right, epsilon) → Boolean
Core/Quaternion.js 1003

Compares this and the provided quaternion componentwise and returns `true` if they are within the provided epsilon, `false` otherwise.

Name | Type | Default | Description
--- | --- | --- | ---
`right` | Quaternion |  | optional The right hand side quaternion.
`epsilon` | Number | `0` | optional The epsilon to use for equality testing.

##### Returns:

`true` if left and right are within the provided epsilon, `false` otherwise.

#### toString() → String
Core/Quaternion.js 1012

Returns a string representing this quaternion in the format (x, y, z, w).

##### Returns:

A string representing this Quaternion.