Package jme3utilities.math
Class MyQuaternion
java.lang.Object
jme3utilities.math.MyQuaternion
Mathematical utility methods.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaccumulateScaled(com.jme3.math.Quaternion total, com.jme3.math.Quaternion input, float scale) Accumulate a linear combination of quaternions.static floatangleBetween(com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2) Returns the angle (in radians) between the specified quaternions, provided both are normalized.static voidcardinalizeLocal(com.jme3.math.Quaternion input) Find the cardinal rotation most similar to the specified input.static com.jme3.math.Quaternionconjugate(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the conjugate of a Quaternion.static intcountNe(com.jme3.math.Quaternion[] quaternions) Count the number of distinct quaternions, without distinguishing 0 from -0.static Stringdescribe(com.jme3.math.Quaternion q) Generate a textual description of a Quaternion value.static doubledot(com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2) Determine the dot (scalar) product of 2 quaternions.static com.jme3.math.Quaternionexp(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the exponential of a pure Quaternion.static booleanisPure(com.jme3.math.Quaternion q) Test for a pure Quaternion.static booleanisRotationIdentity(com.jme3.math.Quaternion q) Test whether the specified Quaternion represents an identity rotation.static booleanisZero(com.jme3.math.Quaternion q) Test for a zero Quaternion.static doublelengthSquared(com.jme3.math.Quaternion q) Determine the squared length of a Quaternion.static com.jme3.math.Quaternionlog(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the natural logarithm of a unit quaternion.static com.jme3.math.QuaternionmirrorAxis(com.jme3.math.Quaternion input, int axisIndex, com.jme3.math.Quaternion storeResult) Mirror the specified Quaternion along the indexed axis.static booleanne(com.jme3.math.Quaternion a, com.jme3.math.Quaternion b) Test whether 2 quaternions are distinct, without distinguishing 0 from -0.static voidnormalizeLocal(com.jme3.math.Quaternion input) Normalize the specified Quaternion in place.static com.jme3.math.Quaternionpow(com.jme3.math.Quaternion base, float exponent, com.jme3.math.Quaternion storeResult) Raise a unit quaternion to the specified real power.static com.jme3.math.Quaternionslerp(float t, com.jme3.math.Quaternion q0, com.jme3.math.Quaternion q1, com.jme3.math.Quaternion storeResult) Interpolate between 2 unit quaternions using spherical linear (Slerp) interpolation.static voidsnapLocal(com.jme3.math.Quaternion input, int axisIndex) Round the rotation angle of the indexed axis to the nearest Pi/2 radians.static com.jme3.math.Quaternionsquad(float t, com.jme3.math.Quaternion p, com.jme3.math.Quaternion a, com.jme3.math.Quaternion b, com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Interpolate between 4 unit quaternions using the Squad function.static com.jme3.math.QuaternionsquadA(com.jme3.math.Quaternion q0, com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2, com.jme3.math.Quaternion storeResult) Determine Squad parameter "a" for a continuous first derivative at the middle point of 3 specified control points.static com.jme3.math.Quaternionstandardize(com.jme3.math.Quaternion input, com.jme3.math.Quaternion storeResult) Standardize a Quaternion in preparation for hashing.static booleanvalidateUnit(com.jme3.math.Quaternion q, String description, float tolerance) Validate a unit quaternion as a method argument.
-
Field Details
-
logger
message logger for this class
-
-
Method Details
-
accumulateScaled
public static void accumulateScaled(com.jme3.math.Quaternion total, com.jme3.math.Quaternion input, float scale) Accumulate a linear combination of quaternions.- Parameters:
total- sum of the scaled inputs so far (not null, modified, may beinput)input- the Quaternion to scale and add (not null, unaffected unless it'stotal)scale- scale factor to apply to the input
-
angleBetween
public static float angleBetween(com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2) Returns the angle (in radians) between the specified quaternions, provided both are normalized.- Parameters:
q1- the first quaternion (not null, norm=1)q2- the other quaternions (not null, norm=1)- Returns:
- the angle (in radians, not negative)
-
cardinalizeLocal
public static void cardinalizeLocal(com.jme3.math.Quaternion input) Find the cardinal rotation most similar to the specified input. A cardinal rotation is one for which the rotation angles on all 3 axes are integer multiples of Pi/2 radians.- Parameters:
input- (not null, modified)
-
conjugate
public static com.jme3.math.Quaternion conjugate(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the conjugate of a Quaternion. For unit quaternions, the conjugate is a faster way to calculate the inverse.- Parameters:
q- input value (not null, unaffected unless it'sstoreResult)storeResult- storage for the result (modified if not null, may beq)- Returns:
- a conjugate quaternion (either storeResult or a new instance)
-
countNe
public static int countNe(com.jme3.math.Quaternion[] quaternions) Count the number of distinct quaternions, without distinguishing 0 from -0.- Parameters:
quaternions- (unaffected)- Returns:
- the count (≥0)
-
describe
Generate a textual description of a Quaternion value.- Parameters:
q- the value to describe (may be null, unaffected)- Returns:
- a description (not null, not empty)
-
dot
public static double dot(com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2) Determine the dot (scalar) product of 2 quaternions. UnlikeQuaternion.dot(com.jme3.math.Quaternion), this method returns a double-precision value for precise calculation of angles.- Parameters:
q1- the first Quaternion (not null, unaffected)q2- the 2nd Quaternion (not null, unaffected)- Returns:
- the dot product
-
exp
public static com.jme3.math.Quaternion exp(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the exponential of a pure Quaternion.- Parameters:
q- input value (not null, unaffected, w=0)storeResult- storage for the result (modified if not null)- Returns:
- a unit quaternion (either storeResult or a new instance)
-
isPure
public static boolean isPure(com.jme3.math.Quaternion q) Test for a pure Quaternion.- Parameters:
q- the input (not null, unaffected)- Returns:
- true if w=0, false otherwise
-
isRotationIdentity
public static boolean isRotationIdentity(com.jme3.math.Quaternion q) Test whether the specified Quaternion represents an identity rotation. This test is weaker than that implemented byQuaternion.isIdentity()because it accepts any non-zero value for w.- Parameters:
q- input value (not null, unaffected)- Returns:
- true for a rotation identity, otherwise false
-
isZero
public static boolean isZero(com.jme3.math.Quaternion q) Test for a zero Quaternion.- Parameters:
q- the input (not null, unaffected)- Returns:
- true if the Quaternion equals (0,0,0,0), false otherwise
-
lengthSquared
public static double lengthSquared(com.jme3.math.Quaternion q) Determine the squared length of a Quaternion. UnlikeQuaternion.norm(), this method returns a double-precision value for precise comparison of lengths.- Parameters:
q- input (not null, unaffected)- Returns:
- the squared length (≥0)
-
log
public static com.jme3.math.Quaternion log(com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Determine the natural logarithm of a unit quaternion. Generally the logarithm isn't itself a unit.- Parameters:
q- input value (not null, unaffected unless it'sstoreResult, norm=1)storeResult- storage for the result (modified if not null, may beq)- Returns:
- a pure Quaternion (either storeResult or a new instance)
-
mirrorAxis
public static com.jme3.math.Quaternion mirrorAxis(com.jme3.math.Quaternion input, int axisIndex, com.jme3.math.Quaternion storeResult) Mirror the specified Quaternion along the indexed axis.- Parameters:
input- the Quaternion to mirror (not null, unaffected unless it'sstoreResult)axisIndex- which axis to mirror: 0→X, 1→Y, 2→ZstoreResult- storage for the result (modified if not null, may beinput)- Returns:
- a mirrored Quaternion (either storeResult or a new instance)
-
ne
public static boolean ne(com.jme3.math.Quaternion a, com.jme3.math.Quaternion b) Test whether 2 quaternions are distinct, without distinguishing 0 from -0.- Parameters:
a- the first input quaternion (not null, unaffected)b- the 2nd input quaternion (not null, unaffected)- Returns:
- true if distinct, otherwise false
-
normalizeLocal
public static void normalizeLocal(com.jme3.math.Quaternion input) Normalize the specified Quaternion in place. This method is less vulnerable to overflow thanQuaternion.normalizeLocal().- Parameters:
input- (not null, modified)
-
pow
public static com.jme3.math.Quaternion pow(com.jme3.math.Quaternion base, float exponent, com.jme3.math.Quaternion storeResult) Raise a unit quaternion to the specified real power.- Parameters:
base- input value (not null, unaffected unless it'sstoreResult, norm=1)exponent- the exponentstoreResult- storage for the result (modified if not null, may bebase)- Returns:
- a unit quaternion (either storeResult or a new instance)
-
slerp
public static com.jme3.math.Quaternion slerp(float t, com.jme3.math.Quaternion q0, com.jme3.math.Quaternion q1, com.jme3.math.Quaternion storeResult) Interpolate between 2 unit quaternions using spherical linear (Slerp) interpolation. This method is slower (but more accurate) thanQuaternion.slerp(com.jme3.math.Quaternion, float), always produces a unit, and doesn't trash q1. The caller is responsible for flipping the sign of q0 or q1 when it's appropriate to do so.- Parameters:
t- descaled parameter value (≥0, ≤1)q0- function value at t=0 (not null, unaffected unless it'sstoreResult, norm=1)q1- function value at t=1 (not null, unaffected unless it'sstoreResult, norm=1)storeResult- storage for the result (modified if not null, may beq0orq1)- Returns:
- an interpolated unit quaternion (either storeResult or a new instance)
-
snapLocal
public static void snapLocal(com.jme3.math.Quaternion input, int axisIndex) Round the rotation angle of the indexed axis to the nearest Pi/2 radians.- Parameters:
input- (not null, modified)axisIndex- which axis (≥0, <3)
-
squad
public static com.jme3.math.Quaternion squad(float t, com.jme3.math.Quaternion p, com.jme3.math.Quaternion a, com.jme3.math.Quaternion b, com.jme3.math.Quaternion q, com.jme3.math.Quaternion storeResult) Interpolate between 4 unit quaternions using the Squad function. The caller is responsible for flipping signs when it's appropriate to do so.- Parameters:
t- descaled parameter value (≥0, ≤1)p- function value at t=0 (not null, unaffected, norm=1)a- the first control point (not null, unaffected, norm=1)b- the 2nd control point (not null, unaffected, norm=1)q- function value at t=1 (not null, unaffected, norm=1)storeResult- storage for the result (modified if not null)- Returns:
- interpolated unit quaternion (either storeResult or a new instance)
-
squadA
public static com.jme3.math.Quaternion squadA(com.jme3.math.Quaternion q0, com.jme3.math.Quaternion q1, com.jme3.math.Quaternion q2, com.jme3.math.Quaternion storeResult) Determine Squad parameter "a" for a continuous first derivative at the middle point of 3 specified control points.- Parameters:
q0- previous control point (not null, unaffected, norm=1)q1- current control point (not null, unaffected, norm=1)q2- following control point (not null, unaffected, norm=1)storeResult- storage for the result (modified if not null)- Returns:
- a unit quaternion for use as a Squad parameter (either storeResult or a new instance)
-
standardize
public static com.jme3.math.Quaternion standardize(com.jme3.math.Quaternion input, com.jme3.math.Quaternion storeResult) Standardize a Quaternion in preparation for hashing.- Parameters:
input- (not null, unaffected unless it'sstoreResult)storeResult- storage for the result (modified if not null, may beinput)- Returns:
- an equivalent Quaternion without negative zeros (either storeResult or a new instance)
-
validateUnit
Validate a unit quaternion as a method argument.- Parameters:
q- Quaternion to validate (not null, unaffected)description- description of the Quaterniontolerance- for the norm (≥0)- Returns:
- true
- Throws:
IllegalArgumentException- if the norm is out of toleranceNullPointerException- if the Quaternion is null
-