public class QuaternionM4D extends Object implements QuaternionReadable4DType, QuaternionWritable4DType
Values of this type cannot be accessed safely from multiple threads without explicit synchronization.
| Modifier and Type | Class and Description |
|---|---|
static class |
QuaternionM4D.Context
The Context type contains the minimum storage required for all of the
functions of the
QuaternionM4D class. |
| Constructor and Description |
|---|
QuaternionM4D()
Default constructor, initializing the quaternion with values
[0.0, 0.0, 0.0, 1.0] |
QuaternionM4D(double in_x,
double in_y,
double in_z,
double in_w)
Construct a quaternion initialized with the given values.
|
QuaternionM4D(QuaternionReadable4DType q)
Construct a quaternion initialized with the values given in
q. |
| Modifier and Type | Method and Description |
|---|---|
static QuaternionM4D |
add(QuaternionReadable4DType q0,
QuaternionReadable4DType q1,
QuaternionM4D out)
Calculate the element-wise sum of the quaternions
q0 and
q1, saving the result to qr. |
static QuaternionM4D |
addInPlace(QuaternionM4D q0,
QuaternionReadable4DType q1)
Calculate the element-wise sum of the quaternions
q0 and
q1, saving the result to q0. |
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 QuaternionM4D |
conjugate(QuaternionReadable4DType q,
QuaternionM4D out)
Calculate the conjugate of the input quaternion
q, saving
the result to out. |
static QuaternionM4D |
conjugateInPlace(QuaternionM4D q)
Calculate the conjugate of the input quaternion
q, modifying
q in place. |
static QuaternionM4D |
copy(QuaternionReadable4DType q,
QuaternionM4D out)
Copy the contents of the quaternion
q to out. |
void |
copyFrom2D(VectorReadable2DType in_v)
Set the current vector to the contents of the input vector.
|
void |
copyFrom3D(VectorReadable3DType in_v)
Set the current vector to the contents of the input vector.
|
void |
copyFrom4D(VectorReadable4DType in_v)
Set the current vector to the contents of the input vector.
|
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 QuaternionM4D |
interpolateLinear(QuaternionReadable4DType q0,
QuaternionReadable4DType q1,
double alpha,
QuaternionM4D r)
Linearly interpolate between
q0 and q1 by the
amount alpha, such that:
interpolateLinear(q0, q1, 0.0, r) -> r = q0
interpolateLinear(q0, q1, 1.0, r) -> r = q1
|
static boolean |
isNegationOf(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
Return
true iff qa is the negation of
qb. |
static QuaternionM4D |
lookAtWithContext(QuaternionM4D.Context context,
VectorReadable3DType origin,
VectorReadable3DType target,
VectorReadable3DType up,
QuaternionM4D q)
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, saving the result to
q. |
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 QuaternionM4D |
makeFromAxisAngle(VectorReadable3DType axis,
double angle,
QuaternionM4D out)
Produce a quaternion that represents a rotation of
angle
degrees around the axis specified by axis, saving the result
to out. |
static QuaternionM4D |
makeFromRotationMatrix3x3(MatrixReadable3x3DType m,
QuaternionM4D out)
Produce a quaternion equivalent to the rotation matrix
m,
writing the result to out. |
static QuaternionM4D |
makeFromRotationMatrix4x4(MatrixReadable4x4DType m,
QuaternionM4D out)
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 QuaternionM4D |
multiply(QuaternionReadable4DType q0,
QuaternionReadable4DType q1,
QuaternionM4D qr)
Multiply the quaternion
q0 by the quaternion q1
, saving the result to qr. |
static QuaternionM4D |
multiplyInPlace(QuaternionM4D q0,
QuaternionReadable4DType q1)
Multiply the quaternion
q0 by the quaternion q1
, saving the result to q0. |
static QuaternionM4D |
negate(QuaternionReadable4DType qa,
QuaternionM4D out)
Negate the elements of
qa, writing the resulting quaternion
to out. |
static QuaternionM4D |
negateInPlace(QuaternionM4D q)
Negate the elements of
q, modifying the quaternion in-place. |
static QuaternionM4D |
normalize(QuaternionReadable4DType q,
QuaternionM4D out)
Returns a quaternion with the same orientation as
q but with
magnitude equal to 1.0 in out. |
static QuaternionM4D |
normalizeInPlace(QuaternionM4D q)
Returns a quaternion with the same orientation as
q but with
magnitude equal to 1.0 in q. |
static QuaternionM4D |
scale(QuaternionReadable4DType q,
double r,
QuaternionM4D out)
Scale the quaternion
q by the scalar r, saving
the result to out. |
static QuaternionM4D |
scaleInPlace(QuaternionM4D q,
double r)
Scale the quaternion
q by the scalar r, saving
the result to q. |
void |
set2D(double in_x,
double in_y)
Set the current
x and y values of the current
vector. |
void |
set3D(double in_x,
double in_y,
double in_z)
Set the current
x, y and z values
of the current vector. |
void |
set4D(double in_x,
double in_y,
double in_z,
double in_w)
Set the current
x, y, z and
w values of the current vector. |
void |
setWD(double in_w)
Set the current
w value of the current vector. |
void |
setXD(double in_x)
Set the current
x value of the current vector. |
void |
setYD(double in_y)
Set the current
y value of the current vector. |
void |
setZD(double in_z)
Set the current
z value of the current vector. |
static QuaternionM4D |
subtract(QuaternionReadable4DType q0,
QuaternionReadable4DType q1,
QuaternionM4D out)
Subtract the quaternion
q0 from the quaternion
q1, saving the result to out. |
static QuaternionM4D |
subtractInPlace(QuaternionM4D q0,
QuaternionReadable4DType q1)
Subtract the quaternion
q0 from the quaternion
q1, saving the result to q0. |
String |
toString() |
public QuaternionM4D()
[0.0, 0.0, 0.0, 1.0]public QuaternionM4D(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 QuaternionM4D(QuaternionReadable4DType q)
q.q - The source quaternionpublic static final QuaternionM4D add(QuaternionReadable4DType q0, QuaternionReadable4DType q1, QuaternionM4D out)
q0 and
q1, saving the result to qr.q0 - The left input quaternionq1 - The right input quaternionout - The output quaternion(q0.x + q1.x, q0.y + q1.y, q0.z + q1.z, q0.w + q1.w)public static final QuaternionM4D addInPlace(QuaternionM4D q0, QuaternionReadable4DType q1)
q0 and
q1, saving the result to q0.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 QuaternionM4D conjugate(QuaternionReadable4DType q, QuaternionM4D out)
q, saving
the result to out.q - The input quaternionout - The output quaternionoutpublic static final QuaternionM4D conjugateInPlace(QuaternionM4D q)
q, modifying
q in place.q - The input quaternionqpublic static final QuaternionM4D copy(QuaternionReadable4DType q, QuaternionM4D out)
q to out.q - The input quaternionout - The output quaternionoutpublic static final double dotProduct(QuaternionReadable4DType q0, QuaternionReadable4DType q1)
q0 and
q1.q0 - The left input quaternionq1 - The right input quaternionpublic static final QuaternionM4D interpolateLinear(QuaternionReadable4DType q0, QuaternionReadable4DType q1, double alpha, QuaternionM4D r)
q0 and q1 by the
amount alpha, such that:
interpolateLinear(q0, q1, 0.0, r) -> r = q0interpolateLinear(q0, q1, 1.0, r) -> r = q1q0 - The left input quaternionq1 - The right input quaternionalpha - The interpolation value, between 0.0 and
1.0r - The output quaternion(1 - alpha) * q0 + alpha * q1public static final boolean isNegationOf(com.io7m.jequality.AlmostEqualDouble.ContextRelative context,
QuaternionReadable4DType qa,
QuaternionReadable4DType qb)
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 QuaternionM4D lookAtWithContext(QuaternionM4D.Context context, VectorReadable3DType origin, VectorReadable3DType target, VectorReadable3DType up, QuaternionM4D q)
target assuming the viewer is at origin,
using up as the "up" vector, saving the result to
q.
The function uses storage preallocated in context to avoid
any new allocations.
context - Preallocated storageq - The output quaternionorigin - The origin pointtarget - The target pointup - The up vectorqpublic 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 QuaternionM4D makeFromAxisAngle(VectorReadable3DType axis, double angle, QuaternionM4D out)
angle
degrees around the axis specified by axis, saving the result
to out. axis is assumed to be of unit length.axis - The normalized quaternion representing the axisangle - The angle to rotate, in radiansout - The output quaternionVectorI3D.normalize(VectorReadable3DType),
VectorI4D.normalize(VectorReadable4DType),
VectorM3D.normalize(VectorReadable3DType, VectorM3D),
VectorM4D.normalize(VectorReadable4DType, VectorM4D)public static final QuaternionM4D makeFromRotationMatrix3x3(MatrixReadable3x3DType m, QuaternionM4D out)
m,
writing the result to out.m - The rotation matrixout - The output quaternionoutpublic static final QuaternionM4D makeFromRotationMatrix4x4(MatrixReadable4x4DType m, QuaternionM4D out)
m,
writing the result to out.m - The rotation matrixout - The output quaternionoutpublic 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 QuaternionM4D multiply(QuaternionReadable4DType q0, QuaternionReadable4DType q1, QuaternionM4D qr)
q0 by the quaternion q1
, saving the result to qr.
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 qr that represents
a rotation around the X axis, followed by a rotation around the Y axis,
followed by a rotation around the Z axis:
QuaternionM4D qr = new QuaternionM4D(); QuaternionM4D.multiply(qy, qx, qr); QuaternionM4D.multiply(qz, qr, qr);
q0 - The left input quaternionq1 - The right input quaternionqr - The output quaternionqrpublic static final QuaternionM4D multiplyInPlace(QuaternionM4D q0, QuaternionReadable4DType q1)
q0 by the quaternion q1
, saving the result to q0.q0 - The left quaternionq1 - The right quaternionmultiply(QuaternionReadable4DType,
QuaternionReadable4DType, QuaternionM4D)public static final QuaternionM4D negate(QuaternionReadable4DType qa, QuaternionM4D out)
qa, writing the resulting quaternion
to out.qa - The input quaternionout - The output quaternionpublic static final QuaternionM4D negateInPlace(QuaternionM4D q)
q, modifying the quaternion in-place.q - The input quaternionpublic static final QuaternionM4D normalize(QuaternionReadable4DType q, QuaternionM4D out)
q but with
magnitude equal to 1.0 in out. The function
returns the zero quaternion iff the input is the zero quaternion.out - The output quaternionq - The input quaternionpublic static final QuaternionM4D normalizeInPlace(QuaternionM4D q)
q but with
magnitude equal to 1.0 in q. The function
returns the zero quaternion iff the input is the zero quaternion.q - The input quaternionpublic static final QuaternionM4D scale(QuaternionReadable4DType q, double r, QuaternionM4D out)
q by the scalar r, saving
the result to out.q - The input quaternionr - The scaling valueout - The output quaternion(q.x * r, q.y * r, q.z * r, q.w * r)public static final QuaternionM4D scaleInPlace(QuaternionM4D q, double r)
q by the scalar r, saving
the result to q.q - The input quaternionr - The scaling value(q.x * r, q.y * r, q.z * r, q.w * r)public static final QuaternionM4D subtract(QuaternionReadable4DType q0, QuaternionReadable4DType q1, QuaternionM4D out)
q0 from the quaternion
q1, saving the result to out.q0 - The left input quaternionq1 - The right input quaternionout - The output quaternion(q0.x - q1.x, q0.y - q1.y, q0.z - q1.z, q0.w - q1.w)public static final QuaternionM4D subtractInPlace(QuaternionM4D q0, QuaternionReadable4DType q1)
q0 from the quaternion
q1, saving the result to q0.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 final void copyFrom2D(VectorReadable2DType in_v)
VectorWritable2DTypecopyFrom2D in interface VectorWritable2DTypein_v - The input vectorpublic final void copyFrom3D(VectorReadable3DType in_v)
VectorWritable3DTypecopyFrom3D in interface VectorWritable3DTypein_v - The input vectorpublic final void copyFrom4D(VectorReadable4DType in_v)
VectorWritable4DTypecopyFrom4D in interface VectorWritable4DTypein_v - The input vectorpublic 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 VectorReadable3DTypepublic final void set2D(double in_x,
double in_y)
VectorWritable2DTypex and y values of the current
vector.set2D in interface VectorWritable2DTypein_x - The new x value.in_y - The new y value.public final void set3D(double in_x,
double in_y,
double in_z)
VectorWritable3DTypex, y and z values
of the current vector.set3D in interface VectorWritable3DTypein_x - The new x value.in_y - The new y value.in_z - The new z value.public final void set4D(double in_x,
double in_y,
double in_z,
double in_w)
VectorWritable4DTypex, y, z and
w values of the current vector.set4D in interface VectorWritable4DTypein_x - The new x value.in_y - The new y value.in_z - The new z value.in_w - The new w value.public final void setWD(double in_w)
VectorWritable4DTypew value of the current vector.setWD in interface VectorWritable4DTypein_w - The new w value.public final void setXD(double in_x)
VectorWritable2DTypex value of the current vector.setXD in interface VectorWritable2DTypein_x - The new x value.public final void setYD(double in_y)
VectorWritable2DTypey value of the current vector.setYD in interface VectorWritable2DTypein_y - The new y value.public final void setZD(double in_z)
VectorWritable3DTypez value of the current vector.setZD in interface VectorWritable3DTypein_z - The new z value.Copyright © 2014 <code@io7m.com> http://io7m.com