Class Quaternions4D
Functions over Quaternion4D values.
See "Mathematics for 3D Game Programming and Computer Graphics" 2nd Ed for the derivations of most of the code in this class (ISBN: 1-58450-277-0).
- Since:
- 8.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe type of comparison functions for values of typeQuaternion4D. -
Method Summary
Modifier and TypeMethodDescriptionstatic Quaternion4Dadd(Quaternion4D q0, Quaternion4D q1) Addq0toq1.static Quaternion4DCalculate the conjugate of the input quaternionq.static doubledotProduct(Quaternion4D q0, Quaternion4D q1) Calculate the scalar product of the quaternionsq0andq1.static Quaternion4Didentity()The identity quaternion.static Quaternion4DinterpolateLinear(Quaternion4D q0, Quaternion4D q1, double alpha) Linearly interpolate betweenq0andq1by the amountalpha, such that:static Quaternion4DinterpolateSphericalLinear(Quaternion4D q0, Quaternion4D q1, double alpha) Interpolate betweenq0andq1, using spherical linear interpolation, by the amountalpha, such that:static booleanReturntrueiffqais the negation ofqb.static doubleCalculate the magnitude of the quaternionq0.static doubleCalculate the squared magnitude of the quaternionq0.static Quaternion4Dmultiply(Quaternion4D q0, Quaternion4D q1) Multiply the quaternionq0by the quaternionq1.static Quaternion4DCalculate the negation of the input quaternionq.static Quaternion4DNormalize the quaternionq0.static Quaternion4DofAxisAngle(double axis_x, double axis_y, double axis_z, double r) Calculate a quaternion that represents a rotation ofrradians around the axis(axis_x, axis_y, axis_z).static Quaternion4DCalculate a quaternion that represents the rotation given by the matrixm.static <A,B> Quaternion4D ofPMatrix4x4(PMatrix4x4D<A, B> m) Calculate a quaternion that represents the rotation given by the matrixm.static Quaternion4Dscale(Quaternion4D q0, double r) Scaleq0byr.static Quaternion4Dsubtract(Quaternion4D q0, Quaternion4D q1) Addq0toq1.static Matrix4x4DCreate a 4x4 matrix from the quaternionq.static <A,B> PMatrix4x4D <A, B> Create a 4x4 matrix from the quaternionq.static Quaternion4Dzero()The zero quaternion.
-
Method Details
-
add
Addq0toq1.- Parameters:
q0- The left quaternionq1- The right quaternion- Returns:
(q0.x + q1.x, q0.y + q0.y, q0.z + q1.z, q0.w + q1.w)
-
conjugate
Calculate the conjugate of the input quaternionq.- Parameters:
q- The input quaternion- Returns:
- The conjugate of the input quaternion
-
dotProduct
Calculate the scalar product of the quaternionsq0andq1.- Parameters:
q0- The left input quaternionq1- The right input quaternion- Returns:
- The scalar product of the two quaternions
-
identity
-
interpolateLinear
Linearly interpolate between
q0andq1by the amountalpha, such that:interpolateLinear(q0, q1, 0.0) = q0interpolateLinear(q0, q1, 1.0) = q1
- Parameters:
q0- The left input quaternionq1- The right input quaternionalpha- The interpolation value, between0.0and1.0- Returns:
(1 - alpha) * q0 + alpha * q1
-
interpolateSphericalLinear
public static Quaternion4D interpolateSphericalLinear(Quaternion4D q0, Quaternion4D q1, double alpha) Interpolate between
q0andq1, using spherical linear interpolation, by the amountalpha, such that:interpolateSphericalLinear(q0, q1, 0.0) = normalize(q0)interpolateSphericalLinear(q0, q1, 1.0) = normalize(q1)
Note that unlike simple linear interpolation, this function is guaranteed to return a normalized quaternion.
- Parameters:
q0- The left input quaternionq1- The right input quaternionalpha- The interpolation value, between0.0and1.0- Returns:
- A spherical-linearly interpolated quaternion between
q0andq1
-
isNegationOf
public static boolean isNegationOf(Quaternions4D.ComponentComparatorType c, Quaternion4D qa, Quaternion4D qb) Return
trueiffqais the negation ofqb.- Parameters:
qa- The left quaternionqb- The right quaternion- Returns:
trueiffqais the negation ofqb
-
magnitudeSquared
Calculate the squared magnitude of the quaternionq0.- Parameters:
q0- The quaternion- Returns:
- The squared magnitude of the quaternion
-
magnitude
Calculate the magnitude of the quaternionq0.- Parameters:
q0- The quaternion- Returns:
- The magnitude of the quaternion
-
multiply
Multiply the quaternion
q0by the quaternionq1.Note that this operation is not commutative.
The function is most often used to concatenate quaternions to combine rotations. As an example, assuming that:
qxrepresents some rotation around the X axisqyrepresents some rotation around the Y axisqzrepresents some rotation around the Z axis
The following code produces a quaternion
qr1that represents a rotation around the X axis, followed by a rotation around the Y axis, followed by a rotation around the Z axis:qr0 = multiply(qy, qx); qr1 = multiply(qz, qy);- Parameters:
q0- The left input quaternionq1- The right input quaternion- Returns:
- The multiplication of the input quaternions
-
normalize
Normalize the quaternion
q0.If the magnitude of the quaternion is zero, the function returns
q0.- Parameters:
q0- The quaternion- Returns:
- A normalized copy of
q0
-
negate
Calculate the negation of the input quaternionq.- Parameters:
q- The input quaternion- Returns:
- The negation of the input quaternion
-
ofAxisAngle
Calculate a quaternion that represents a rotation ofrradians around the axis(axis_x, axis_y, axis_z).- Parameters:
axis_x- The X component of the axisaxis_y- The Y component of the axisaxis_z- The Z component of the axisr- The rotation in radians- Returns:
- A quaternion
-
ofMatrix4x4
Calculate a quaternion that represents the rotation given by the matrixm.- Parameters:
m- The matrix- Returns:
- A quaternion
-
ofPMatrix4x4
Calculate a quaternion that represents the rotation given by the matrixm.- Type Parameters:
A- A phantom type parameter, possibly representing a source coordinate systemB- A phantom type parameter, possibly representing a target coordinate system- Parameters:
m- The matrix- Returns:
- A quaternion
-
scale
Scaleq0byr.- Parameters:
q0- The left quaternionr- The scaling value- Returns:
(q0.x * r, q0.y * r, q0.z * r, q0.w * r)
-
subtract
Addq0toq1.- Parameters:
q0- The left quaternionq1- The right quaternion- Returns:
(q0.x - q1.x, q0.y - q0.y, q0.z - q1.z, q0.w - q1.w)
-
toMatrix4x4
Create a 4x4 matrix from the quaternionq.- Parameters:
q- The quaternion- Returns:
- A matrix based on q
-
toPMatrix4x4
Create a 4x4 matrix from the quaternionq.- Type Parameters:
A- A phantom type parameter, possibly representing a source coordinate systemB- A phantom type parameter, possibly representing a target coordinate system- Parameters:
q- The quaternion- Returns:
- A matrix based on q
-
zero
-