public final class Quaternions4D extends Object
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).
| Modifier and Type | Class and Description |
|---|---|
static interface |
Quaternions4D.ComponentComparatorType
The type of comparison functions for values of type
Quaternion4D. |
| Modifier and Type | Method and Description |
|---|---|
static Quaternion4D |
add(Quaternion4D q0,
Quaternion4D q1)
Add
q0 to q1. |
static Quaternion4D |
conjugate(Quaternion4D q)
Calculate the conjugate of the input quaternion
q. |
static double |
dotProduct(Quaternion4D q0,
Quaternion4D q1)
Calculate the scalar product of the quaternions
q0 and q1. |
static Quaternion4D |
identity()
The identity quaternion.
|
static Quaternion4D |
interpolateLinear(Quaternion4D q0,
Quaternion4D q1,
double alpha)
Linearly interpolate between
q0 and q1 by the amount
alpha, such that: |
static Quaternion4D |
interpolateSphericalLinear(Quaternion4D q0,
Quaternion4D q1,
double alpha)
Interpolate between
q0 and q1, using spherical
linear interpolation, by the amount alpha, such that: |
static boolean |
isNegationOf(Quaternions4D.ComponentComparatorType c,
Quaternion4D qa,
Quaternion4D qb)
Return
true iff qa is the negation of qb. |
static double |
magnitude(Quaternion4D q0)
Calculate the magnitude of the quaternion
q0. |
static double |
magnitudeSquared(Quaternion4D q0)
Calculate the squared magnitude of the quaternion
q0. |
static Quaternion4D |
multiply(Quaternion4D q0,
Quaternion4D q1)
Multiply the quaternion
q0 by the quaternion q1. |
static Quaternion4D |
negate(Quaternion4D q)
Calculate the negation of the input quaternion
q. |
static Quaternion4D |
normalize(Quaternion4D q0)
Normalize the quaternion
q0. |
static Quaternion4D |
ofAxisAngle(double axis_x,
double axis_y,
double axis_z,
double r)
Calculate a quaternion that represents a rotation of
r radians
around the axis (axis_x, axis_y, axis_z). |
static Quaternion4D |
ofMatrix4x4(Matrix4x4D m)
Calculate a quaternion that represents the rotation given by the matrix
m. |
static <A,B> Quaternion4D |
ofPMatrix4x4(PMatrix4x4D<A,B> m)
Calculate a quaternion that represents the rotation given by the matrix
m. |
static Quaternion4D |
scale(Quaternion4D q0,
double r)
Scale
q0 by r. |
static Quaternion4D |
subtract(Quaternion4D q0,
Quaternion4D q1)
Add
q0 to q1. |
static Matrix4x4D |
toMatrix4x4(Quaternion4D q)
Create a 4x4 matrix from the quaternion
q. |
static <A,B> PMatrix4x4D<A,B> |
toPMatrix4x4(Quaternion4D q)
Create a 4x4 matrix from the quaternion
q. |
static Quaternion4D |
zero()
The zero quaternion.
|
public static Quaternion4D add(Quaternion4D q0, Quaternion4D q1)
q0 to q1.q0 - The left quaternionq1 - The right quaternion(q0.x + q1.x, q0.y + q0.y, q0.z + q1.z, q0.w + q1.w) public static Quaternion4D conjugate(Quaternion4D q)
q.q - The input quaternionpublic static double dotProduct(Quaternion4D q0, Quaternion4D q1)
q0 and q1.q0 - The left input quaternionq1 - The right input quaternionpublic static Quaternion4D identity()
(0, 0, 0, 1) public static Quaternion4D interpolateLinear(Quaternion4D q0, Quaternion4D q1, double alpha)
Linearly interpolate between q0 and q1 by the amount
alpha, such that:
interpolateLinear(q0, q1, 0.0) = q0interpolateLinear(q0, q1, 1.0) = q1q0 - The left input quaternionq1 - The right input quaternionalpha - The interpolation value, between 0.0 and 1.0(1 - alpha) * q0 + alpha * q1public static Quaternion4D interpolateSphericalLinear(Quaternion4D q0, Quaternion4D q1, double alpha)
Interpolate between q0 and q1, using spherical
linear interpolation, by the amount alpha, 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.
q0 - The left input quaternionq1 - The right input quaternionalpha - The interpolation value, between 0.0 and 1.0q0 and
q1public static boolean isNegationOf(Quaternions4D.ComponentComparatorType c, Quaternion4D qa, Quaternion4D qb)
Return true iff qa is the negation of qb.
qa - The left quaternionqb - The right quaterniontrue iff qa is the negation of qbpublic static double magnitudeSquared(Quaternion4D q0)
q0.q0 - The quaternionpublic static double magnitude(Quaternion4D q0)
q0.q0 - The quaternionpublic static Quaternion4D multiply(Quaternion4D q0, Quaternion4D q1)
Multiply the quaternion q0 by the quaternion q1.
Note that this operation is not commutative.
The function is most often used to concatenate quaternions to combine rotations. As an example, assuming that:
qx represents some rotation around the X axisqy represents some rotation around the Y axisqz represents some rotation around the Z axisThe following code produces a quaternion qr1 that 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); q0 - The left input quaternionq1 - The right input quaternionpublic static Quaternion4D normalize(Quaternion4D q0)
Normalize the quaternion q0.
If the magnitude of the quaternion is zero, the function returns q0.
q0 - The quaternionq0public static Quaternion4D negate(Quaternion4D q)
q.q - The input quaternionpublic static Quaternion4D ofAxisAngle(double axis_x, double axis_y, double axis_z, double r)
r radians
around the axis (axis_x, axis_y, axis_z).r - The rotation in radiansaxis_x - The X component of the axisaxis_y - The Y component of the axisaxis_z - The Z component of the axispublic static Quaternion4D ofMatrix4x4(Matrix4x4D m)
m.m - The matrixpublic static <A,B> Quaternion4D ofPMatrix4x4(PMatrix4x4D<A,B> m)
m.A - A phantom type parameter, possibly representing a source coordinate systemB - A phantom type parameter, possibly representing a target coordinate systemm - The matrixpublic static Quaternion4D scale(Quaternion4D q0, double r)
q0 by r.q0 - The left quaternionr - The scaling value(q0.x * r, q0.y * r, q0.z * r, q0.w * r) public static Quaternion4D subtract(Quaternion4D q0, Quaternion4D q1)
q0 to q1.q0 - The left quaternionq1 - The right quaternion(q0.x - q1.x, q0.y - q0.y, q0.z - q1.z, q0.w - q1.w) public static Matrix4x4D toMatrix4x4(Quaternion4D q)
q.q - The quaternionpublic static <A,B> PMatrix4x4D<A,B> toPMatrix4x4(Quaternion4D q)
q.A - A phantom type parameter, possibly representing a source coordinate systemB - A phantom type parameter, possibly representing a target coordinate systemq - The quaternionpublic static Quaternion4D zero()
(0, 0, 0, 0) Copyright © 2017 <code@io7m.com> http://io7m.com