public class QuaternionI4D extends Object implements QuaternionReadable4DType
Values of this type are immutable and can therefore be safely accessed from multiple threads.
| Modifier and Type | Class and Description |
|---|---|
static class |
QuaternionI4D.Context
The Context type contains the minimum storage required for all of the
functions of the
QuaternionI4D class. |
| Modifier and Type | Field and Description |
|---|---|
static QuaternionI4D |
IDENTITY
The "identity" quaternion, [0.0 0.0 0.0 1.0]
|
| Constructor and Description |
|---|
QuaternionI4D()
Default constructor, initializing the quaternion with values
[0.0, 0.0, 0.0, 1.0] |
QuaternionI4D(double in_x,
double in_y,
double in_z,
double in_w)
Construct a quaternion initialized with the given values.
|
QuaternionI4D(QuaternionReadable4DType q)
Construct a quaternion initialized with the values contained in
q. |
| Modifier and Type | Method and Description |
|---|---|
static QuaternionI4D |
add(QuaternionReadable4DType q0,
QuaternionReadable4DType q1)
Calculate the element-wise sum of the quaternions
q0 and
q1. |
static boolean |
almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
Determine whether or not the quaternions
qa and
qb are equal to within the degree of error given in
context. |
static QuaternionI4D |
conjugate(QuaternionReadable4DType q)
Calculate the conjugate of the input quaternion
q. |
static double |
dotProduct(QuaternionReadable4DType q0,
QuaternionReadable4DType q1)
Calculate the scalar product of the quaternions
q0 and
q1. |
boolean |
equals(Object obj) |
double |
getWD() |
double |
getXD() |
double |
getYD() |
double |
getZD() |
int |
hashCode() |
static QuaternionI4D |
interpolateLinear(QuaternionReadable4DType q0,
QuaternionReadable4DType q1,
double alpha)
Linearly interpolate between
q0 and q1 by the
amount alpha, such that:
interpolateLinear(q0, q1, 0.0) = q0
interpolateLinear(q0, q1, 1.0) = q1
|
static boolean |
isNegationOf(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
Return
true iff qa is the negation of
qb. |
static QuaternionI4D |
lookAtWithContext(QuaternionI4D.Context context,
VectorReadable3DType origin,
VectorReadable3DType target,
VectorReadable3DType up)
Produce a quaternion that represents a rotation that "looks at" the point
at
target assuming the viewer is at origin,
using up as the "up" vector. |
static double |
magnitude(QuaternionReadable4DType q)
Calculate the magnitude of the quaternion
q. |
static double |
magnitudeSquared(QuaternionReadable4DType q)
Calculate the squared magnitude of the quaternion
q. |
static QuaternionI4D |
makeFromAxisAngle(VectorReadable3DType axis,
double angle)
Produce a quaternion that represents a rotation of
angle
degrees around the axis specified by axis. |
static QuaternionI4D |
makeFromRotationMatrix3x3(MatrixReadable3x3DType m)
Produce a quaternion equivalent to the rotation matrix
m. |
static QuaternionI4D |
makeFromRotationMatrix4x4(MatrixReadable4x4DType m)
Produce a quaternion equivalent to the rotation matrix
m,
writing the result to out. |
static MatrixM3x3D |
makeRotationMatrix3x3(QuaternionReadable4DType q,
MatrixM3x3D m)
Produce a rotation matrix from the quaternion
q, saving the
result to m. |
static MatrixM4x4D |
makeRotationMatrix4x4(QuaternionReadable4DType q,
MatrixM4x4D m)
Produce a rotation matrix from the quaternion
q, saving the
result to m. |
static QuaternionI4D |
multiply(QuaternionReadable4DType q0,
QuaternionReadable4DType q1)
Multiply the quaternion
q0 by the quaternion q1
. |
static QuaternionI4D |
negate(QuaternionReadable4DType q)
Negate the elements of
q. |
static QuaternionI4D |
normalize(QuaternionReadable4DType q)
Normalize the quaternion
q, preserqing its direction but
reducing it to unit length. |
static QuaternionI4D |
scale(QuaternionReadable4DType q,
double r)
Scale the quaternion
q by the scalar r. |
static QuaternionI4D |
subtract(QuaternionReadable4DType q0,
QuaternionReadable4DType q1)
Subtract the quaternion
q0 from the quaternion
q1. |
String |
toString() |
public static final QuaternionI4D IDENTITY
public QuaternionI4D()
[0.0, 0.0, 0.0, 1.0]public QuaternionI4D(double in_x,
double in_y,
double in_z,
double in_w)
in_x - The x valuein_y - The y valuein_z - The z valuein_w - The w valuepublic QuaternionI4D(QuaternionReadable4DType q)
q.q - The source quaternionpublic static final QuaternionI4D add(QuaternionReadable4DType q0, QuaternionReadable4DType q1)
q0 and
q1.q0 - The left input quaternionq1 - The right input quaternion(q0.x + q1.x, q0.y + q1.y, q0.z + q1.z, q0.w + q1.w)public static final boolean almostEqual(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
qa and
qb are equal to within the degree of error given in
context.context - The equality contextqa - The left input quaternionqb - The right input quaterniontrue if the quaternions are almost equalAlmostEqualDouble.almostEqual(ContextRelative, double, double)public static final QuaternionI4D conjugate(QuaternionReadable4DType q)
q.q - The input quaternionpublic static final double dotProduct(QuaternionReadable4DType q0, QuaternionReadable4DType q1)
q0 and
q1.q0 - The left input quaternionq1 - The right input quaternionpublic static final QuaternionI4D interpolateLinear(QuaternionReadable4DType q0, QuaternionReadable4DType q1, double alpha)
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 final boolean isNegationOf(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
Return true iff qa is the negation of
qb.
Each element is compared with
AlmostEqualDouble.almostEqual(ContextRelative, double, double).
context - The equality contextqa - The left quaternionqb - The right quaterniontrue iff qa is the negation of
qbpublic static final QuaternionI4D lookAtWithContext(QuaternionI4D.Context context, VectorReadable3DType origin, VectorReadable3DType target, VectorReadable3DType up)
Produce a quaternion that represents a rotation that "looks at" the point
at target assuming the viewer is at origin,
using up as the "up" vector.
The function uses storage preallocated in context to avoid
any new allocations.
context - Preallocated storageorigin - The origin pointtarget - The target pointup - The up vectorpublic static final double magnitude(QuaternionReadable4DType q)
q.
Correspondingly, magnitude(normalize(q)) == 1.0.q - The input quaternionpublic static final double magnitudeSquared(QuaternionReadable4DType q)
q.q - The input quaternionpublic static final QuaternionI4D makeFromAxisAngle(VectorReadable3DType axis, double angle)
angle
degrees around the axis specified by axis. axis
is assumed to be of unit length.axis - The normalized vector representing the axisangle - The angle to rotate, in radiansVectorI3D.normalize(VectorReadable3DType),
VectorI4D.normalize(VectorReadable4DType)public static final QuaternionI4D makeFromRotationMatrix3x3(MatrixReadable3x3DType m)
m.m - The rotation matrixpublic static final QuaternionI4D makeFromRotationMatrix4x4(MatrixReadable4x4DType m)
m,
writing the result to out.m - The rotation matrixpublic static final MatrixM3x3D makeRotationMatrix3x3(QuaternionReadable4DType q, MatrixM3x3D m)
q, saving the
result to m.q - The input quaternionm - The output matrixmpublic static final MatrixM4x4D makeRotationMatrix4x4(QuaternionReadable4DType q, MatrixM4x4D m)
q, saving the
result to m.q - The input quaternionm - The output matrixmpublic static final QuaternionI4D multiply(QuaternionReadable4DType q0, QuaternionReadable4DType q1)
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 axis
The 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 = QuaternionI4D.multiply(qy, qx);
qr1 = QuaternionI4D.multiply(qz, qy);
q0 - The left input quaternionq1 - The right input quaternionpublic static final QuaternionI4D negate(QuaternionReadable4DType q)
q.q - The source quaternionqpublic static final QuaternionI4D normalize(QuaternionReadable4DType q)
q, preserqing its direction but
reducing it to unit length.q - The input quaternionq but with
magnitude equal to 1.0public static final QuaternionI4D scale(QuaternionReadable4DType q, double r)
q by the scalar r.q - The input quaternionr - The scaling value(q.x * r, q.y * r, q.z * r, q.w * r)public static final QuaternionI4D subtract(QuaternionReadable4DType q0, QuaternionReadable4DType q1)
q0 from the quaternion
q1.q0 - The left input quaternionq1 - The right input quaternion(q0.x - q1.x, q0.y - q1.y, q0.z - q1.z)public final double getWD()
getWD in interface VectorReadable4DTypepublic final double getXD()
getXD in interface VectorReadable2DTypepublic final double getYD()
getYD in interface VectorReadable2DTypepublic final double getZD()
getZD in interface VectorReadable3DTypeCopyright © 2015 <code@io7m.com> http://io7m.com