Class: Quaternion

Quaternion

new Quaternion(x, y, z, w)

A set of four-dimensional coordinates used to represent rotation in three-dimensional space.

Name Type Default Description
x Number 0.0 optional

Part X.

y Number 0.0 optional

Part Y.

z Number 0.0 optional

Part Z.

w Number 0.0 optional

Part W.

See:
  • PackableForInterpolation

Members

(static, constant) IDENTITYQuaternion

Initialize as an immutable quaternion instance of (0.0, 0.0, 0.0, 1.0).

static packedInterpolationLengthNumber

The number of elements used to store objects in an array in an interpolated form.

static packedLengthNumber

The number of elements used to package an object into an array.

(static, constant) ZEROQuaternion

Initialize as an immutable quaternion instance of (0.0, 0.0, 0.0, 0.0).

wNumber

Part W.

Default Value:
0.0

xNumber

Part X.

Default Value:
0.0

yNumber

Part Y.

Default Value:
0.0

zNumber

Part Z.

Default Value:
0.0

Methods

static add(left, right, result){Quaternion}

Calculate the sum of the components of two quaternions.

Name Type Description
left Quaternion

The first quaternion.

right Quaternion

The second quaternion.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static clone(quaternion, result){Quaternion}

Copy quaternion instances.

Name Type Description
quaternion Quaternion

The quaternion to be copied.

result Quaternion optional

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if no quaternion instance is provided). If the quaternion is undefined, return undefined.

static computeAngle(quaternion){Number}

Calculate the rotation angle of the provided quaternion.

Name Type Description
quaternion Quaternion

The quaternion to be used.

Returns:
Type Description
Number Rotation angle.

static computeAxis(quaternion, result){Cartesian3}

Calculate the rotation axis of the quaternion provided.

Name Type Description
quaternion Quaternion

The quaternion to be used.

result Cartesian3

The object that stores the results.

Returns:
Type Description
Cartesian3 The modified result parameters.

static computeInnerQuadrangle(q0, q1, q2, result){Quaternion}

Calculate an inner quadrilateral point. This will calculate quaternions to ensure that the lineup 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 that stores the results.

See:
  • Quaternion#squad
Returns:
Type Description
Quaternion The modified result parameters.

static conjugate(quaternion, result){Quaternion}

Calculate the conjugate number of the quaternion provided.

Name Type Description
quaternion Quaternion

A quaternion used for conjugation.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static convertPackedArrayForInterpolation(packedArray, startingIndex, lastIndex, result)

Convert the packaged array into a form suitable for interpolation.

Name Type Default Description
packedArray Array.<Number>

Package the 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>

The object in which to store the results.

static divideByScalar(quaternion, scalar, result){Quaternion}

Divide the provided scalar component by the provided quaternion.

Name Type Description
quaternion Quaternion

The quaternion to be divided.

scalar Number

The scalar to be divided by.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static dot(left, right){Number}

Calculate the point (scalar) product of two quaternions.

Name Type Description
left Quaternion

The first quaternion.

right Quaternion

The second quaternion.

Returns:
Type Description
Number Dot product.

static equals(left, right){Boolean}

Compare the components of the provided quaternions, return true if they are equal, otherwise return false.

Name Type Description
left Quaternion optional

The first quaternion.

right Quaternion optional

The second quaternion.

Returns:
Type Description
Boolean If they are equal, it is true; otherwise, it is false.

static equalsEpsilon(left, right, epsilon){Boolean}

Compare the components of the provided quaternions, return true if they are within the provided range of ε, otherwise return false.

Name Type Description
left Quaternion optional

The first quaternion.

right Quaternion optional

The second quaternion.

epsilon Number

Tolerance values used for equation testing.

Returns:
Type Description
Boolean If within the provided tolerance range, it is true; Otherwise, it is false.

static exp(cartesian, result){Quaternion}

Exponential quaternion function.

Name Type Description
cartesian Cartesian3

cartesian。

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static fastSlerp(start, end, t, result){Quaternion}

Calculate spherical linear interpolation or extrapolation at t using the provided quaternions. This implementation is faster than Quaternion # slip, but can only be precise to 10-6.

Name Type Description
start Quaternion

Corresponding to the value of t at 0.0.

end Quaternion

Corresponding to the value of t at 1.0.

t Number

The point interpolated along t.

result Quaternion

The object that stores the results.

See:
  • Quaternion#slerp
Returns:
Type Description
Quaternion The modified result parameters.

static fastSquad(q0, q1, s0, s1, t, result){Quaternion}

Calculate the spherical quadrilateral interpolation between quaternions. A faster implementation than Quaternion # squad, but not very accurate.

Name Type Description
q0 Quaternion

The first quaternion.

q1 Quaternion

The second quaternion.

s0 Quaternion

The first quadrilateral.

s1 Quaternion

The second quadrilateral.

t Number

The time used for interpolation in [0,1].

result Quaternion

The object that stores the results.

See:
  • Quaternion#squad
Returns:
Type Description
Quaternion The modified result parameters, if not provided, will be a new instance.

static fromAxisAngle(axis, angle, result){Quaternion}

Calculate the quaternion representing rotation around an axis.

Name Type Description
axis Cartesian3

Rotating axis.

angle Number

The angle of rotation around the axis (in radians).

result Quaternion optional

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if not provided).

static fromHeadingPitchRoll(headingPitchRoll, result){Quaternion}

Calculate the rotation angle based on the given azimuth, elevation, and roll angles. The azimuth angle is the rotation around the negative Z-axis. The pitch angle is the rotation angle around the negative y-axis. Rolling is the rotation around the positive x-axis.

Name Type Description
headingPitchRoll HeadingPitchRoll

Rotation represented by azimuth, pitch, and roll.

result Quaternion optional

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if not provided).

static fromRotationMatrix(matrix, result){Quaternion}

Calculate quaternions based on the provided Matrix3 instance.

Name Type Description
matrix Matrix3

Rotation matrix

result Quaternion optional

The object that stores the results.

See:
Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if not provided).

static inverse(quaternion, result){Quaternion}

Calculate the inverse of the quaternion provided.

Name Type Description
quaternion Quaternion

To standardize quaternions.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static lerp(start, end, t, result){Quaternion}

Calculate the linear interpolation or extrapolation value 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=1.0.

t Number

The point interpolated along t.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static log(quaternion, result){Cartesian3}

Logarithmic quaternion function.

Name Type Description
quaternion Quaternion

Unit quaternion.

result Cartesian3

The object that stores the results.

Returns:
Type Description
Cartesian3 The modified result parameters.

static magnitude(quaternion){Number}

Calculate the magnitude of the quaternion provided.

Name Type Description
quaternion Quaternion

To conjugate quaternions.

Returns:
Type Description
Number The magnitude.

static magnitudeSquared(quaternion){Number}

Calculate the square of the amplitude of the quaternion provided.

Name Type Description
quaternion Quaternion

To conjugate quaternions.

Returns:
Type Description
Number The square of the amplitude.

static multiply(left, right, result){Quaternion}

Calculate the product of two quaternions.

Name Type Description
left Quaternion

The first quaternion.

right Quaternion

The second quaternion.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static multiplyByScalar(quaternion, scalar, result){Quaternion}

Multiply the provided quaternion by the provided scalar as a component.

Name Type Description
quaternion Quaternion

The quaternion to be scaled.

scalar Number

The scalar to be multiplied with.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static negate(quaternion, result){Quaternion}

Deny the quaternion provided.

Name Type Description
quaternion Quaternion

The quaternion to be negated.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static normalize(quaternion, result){Quaternion}

Calculate the standardized form of the quaternion provided.

Name Type Description
quaternion Quaternion

To standardize quaternions.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static pack(value, array, startingIndex){Array.<Number>}

Store the provided instance in the provided array.

Name Type Default Description
value Quaternion

The value to be packaged.

array Array.<Number>

The array to be loaded.

startingIndex Number 0 optional

Start packaging the array index of elements.

Returns:
Type Description
Array.<Number> The array that has been loaded.

static slerp(start, end, t, result){Quaternion}

Calculate 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=1.0.

t Number

The point interpolated along t.

result Quaternion

The object that stores the results.

See:
  • Quaternion#fastSlerp
Returns:
Type Description
Quaternion The modified result parameters.

static squad(q0, q1, s0, s1, t, result){Quaternion}

Calculate the spherical quaternion interpolation between quaternions.

Name Type Description
q0 Quaternion

The first quaternion.

q1 Quaternion

The second quaternion.

s0 Quaternion

The first quadrilateral.

s1 Quaternion

The second quadrilateral.

t Number

The time used for interpolation in [0,1].

result Quaternion

The object that stores the results.

See:
  • Quaternion#computeInnerQuadrangle
Returns:
Type Description
Quaternion The modified result parameters.
Example
// 1. compute the squad interpolation between two quaternions on a curve
var s0 = SuperMap3D.Quaternion.computeInnerQuadrangle(quaternions[i - 1], quaternions[i], quaternions[i + 1], new SuperMap3D.Quaternion());
var s1 = SuperMap3D.Quaternion.computeInnerQuadrangle(quaternions[i], quaternions[i + 1], quaternions[i + 2], new SuperMap3D.Quaternion());
var q = SuperMap3D.Quaternion.squad(quaternions[i], quaternions[i + 1], s0, s1, t, new SuperMap3D.Quaternion());

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

static subtract(left, right, result){Quaternion}

Calculate the difference between the components of two quaternions.

Name Type Description
left Quaternion

The first quaternion.

right Quaternion

The second quaternion.

result Quaternion

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters.

static unpack(array, startingIndex, result){Quaternion}

Retrieve instances from the packaged array.

Name Type Default Description
array Array.<Number>

Package the array.

startingIndex Number 0 optional

The starting index of the element to be decompressed.

result Quaternion optional

The object in which to store the results.

Returns:
Type Description
Quaternion The modified result parameters or a new Quaternion instance (if not provided).

static unpackInterpolationResult(array, sourceArray, firstIndex, lastIndex, result){Quaternion}

Read instances from the packaged array converted using convertPackedArrayForInterpolation.

Name Type Default Description
array Array.<Number>

The array previously packaged for interpolation.

sourceArray Array.<Number>

The original packaging array.

firstIndex Number 0 optional

The firstIndex used when converting arrays.

lastIndex Number packedArray.length optional

Used to convert the last index of an array.

result Quaternion optional

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if not provided).

clone(result){Quaternion}

Copy this quaternion instance.

Name Type Description
result Quaternion optional

The object that stores the results.

Returns:
Type Description
Quaternion The modified result parameters, or a new quaternion instance (if not provided).

equals(right){Boolean}

Compare the components of this quaternion with the provided quaternion. If they are equal, return true; otherwise, return false.

Name Type Description
right Quaternion optional

The quaternion on the right.

Returns:
Type Description
Boolean If they are equal, it is true; otherwise, it is false.

equalsEpsilon(right, epsilon){Boolean}

Compare the components of this quaternion with the provided quaternion, return true if within the provided tolerance range, otherwise return false.

Name Type Description
right Quaternion optional

The quaternion on the right.

epsilon Number

Tolerance values used for equation testing.

Returns:
Type Description
Boolean If within the provided tolerance range, it is true; Otherwise, it is false.

toString(){String}

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

Returns:
Type Description
String The string representing this quaternion.