public final class Quaternion extends Object implements IEquatable<Quaternion>, IEquatableEpsilon<Quaternion>, ImmutableValueType
UnitQuaternion is used to represent rotations. This type is available for completeness,
providing quaternion operations on non-normalized quaternions.
For more information on how quaternions and other coordinates are used to represent rotations, see the Coordinates topic.
| Constructor and Description |
|---|
Quaternion()
Initializes a new instance.
|
Quaternion(AngleAxisRotation rotation)
Initializes a set of
Quaternion coordinates from the provided AngleAxisRotation. |
Quaternion(double[] elements)
Initializes a set of
Quaternion coordinates from the first 4 consecutive elements in the provided array. |
Quaternion(double[] elements,
int startIndex)
Initializes a set of
Quaternion coordinates from 4 consecutive elements in the provided array. |
Quaternion(double w,
double x,
double y,
double z)
Initializes a set of
Quaternion coordinates from the provided values. |
Quaternion(ElementaryRotation rotation)
Initializes a set of
Quaternion coordinates from the provided ElementaryRotation. |
Quaternion(EulerSequence sequence)
Initializes a set of
Quaternion coordinates from the provided EulerSequence. |
Quaternion(Matrix3By3 matrix)
Initializes a set of
Quaternion coordinates from the provided Matrix3By3. |
Quaternion(YawPitchRoll sequence)
Initializes a set of
Quaternion coordinates from the provided YawPitchRoll. |
| Modifier and Type | Method and Description |
|---|---|
Quaternion |
conjugate()
Forms the conjugate of this instance, yielding a new
Quaternion. |
boolean |
equals(Object obj)
Indicates whether another object is exactly equal to this instance.
|
static boolean |
equals(Quaternion left,
Quaternion right)
Returns
true if the two instances are exactly equal. |
boolean |
equalsEpsilon(Quaternion other,
double epsilon)
Indicates whether each coordinate value of another instance of this type
is within the required tolerance of the corresponding coordinate value of this instance.
|
boolean |
equalsType(Quaternion other)
Indicates whether another instance of this type is exactly equal to this instance.
|
double |
get(int index)
|
boolean |
getHasZeroNorm()
Gets a value indicating whether the
Norm (get) of this instance is zero. |
static Quaternion |
getIdentity()
Gets the set of
Quaternion coordinates representing the identity vector. |
boolean |
getIsUndefined()
Gets a value indicating whether or not any of the coordinates for this instance have the value
Double.NaN. |
int |
getLength()
Gets the number of elements in this set of coordinates.
|
double |
getNorm()
Gets the norm of this instance.
|
double |
getNormSquared()
Gets the square of the
Norm (get) of this instance. |
static Quaternion |
getUndefined()
Gets a set of
Quaternion coordinates with values of Double.NaN. |
double |
getW()
Gets the W coordinate.
|
double |
getX()
Gets the X coordinate.
|
double |
getY()
Gets the Y coordinate.
|
double |
getZ()
Gets the Z coordinate.
|
static Quaternion |
getZero()
Gets a set of
Quaternion coordinates with values of zero. |
int |
hashCode()
Returns a hash code for this instance, which is suitable for use in hashing algorithms and data structures like a hash table.
|
Quaternion |
multiply(double scalar)
Multiplies this instance by a scalar, yielding a new
Quaternion. |
static Quaternion |
multiply(double scalar,
Quaternion quaternion)
Multiplies a scalar by a specified
Quaternion, yielding a new Quaternion. |
Quaternion |
multiply(ElementaryRotation rotation)
Multiplies this instance by the specified
ElementaryRotation, yielding a new Quaternion. |
Quaternion |
multiply(Quaternion quaternion)
Multiplies this instance by the specified
Quaternion, yielding a new Quaternion. |
static Quaternion |
multiply(Quaternion quaternion,
double scalar)
Multiplies a specified
Quaternion by a scalar, yielding a new Quaternion. |
static Quaternion |
multiply(Quaternion quaternion,
ElementaryRotation rotation)
|
static Quaternion |
multiply(Quaternion left,
Quaternion right)
|
static Quaternion |
negate(Quaternion coordinates)
Negates the specified
Quaternion, yielding a new Quaternion. |
UnitQuaternion |
normalize()
Forms a set of
UnitQuaternion coordinates from this instance. |
UnitQuaternion |
normalize(double[] magnitude)
Forms a set of
UnitQuaternion coordinates from this instance
and returns the magnitude of the original instance in the provided parameter. |
static boolean |
notEquals(Quaternion left,
Quaternion right)
Returns
true if the two instances are not exactly equal. |
static Quaternion |
toQuaternion(UnitQuaternion coordinates)
Converts a set of
UnitQuaternion coordinates to a set of Quaternion coordinates. |
String |
toString()
Returns the string representation of the value of this instance.
|
public Quaternion()
public Quaternion(double w,
double x,
double y,
double z)
Quaternion coordinates from the provided values.w - The W coordinate.x - The X coordinate.y - The Y coordinate.z - The Z coordinate.public Quaternion(@Nonnull EulerSequence sequence)
Quaternion coordinates from the provided EulerSequence.sequence - The Euler sequence of rotations.public Quaternion(@Nonnull YawPitchRoll sequence)
Quaternion coordinates from the provided YawPitchRoll.sequence - The yaw-pitch-roll sequence of rotations.public Quaternion(@Nonnull ElementaryRotation rotation)
Quaternion coordinates from the provided ElementaryRotation.rotation - The elementary rotation.UnsupportedCaseException - Thrown if the Axis (get) property of rotation is
not AxisIndicator.FIRST, AxisIndicator.SECOND, or
AxisIndicator.THIRD.public Quaternion(@Nonnull AngleAxisRotation rotation)
Quaternion coordinates from the provided AngleAxisRotation.rotation - The angle-axis rotation.public Quaternion(@Nonnull Matrix3By3 matrix)
Quaternion coordinates from the provided Matrix3By3.matrix - The 3-by-3 rotation matrix.public Quaternion(@Nonnull double[] elements)
Quaternion coordinates from the first 4 consecutive elements in the provided array.elements - The array of coordinate values.ArgumentNullException - Thrown when elements is null.ArgumentOutOfRangeException - Thrown when an object of this type is constructed from an array with less than 4 elements.public Quaternion(@Nonnull double[] elements, int startIndex)
Quaternion coordinates from 4 consecutive elements in the provided array.elements - The array of coordinate values.startIndex - The index of the first element in the array to use.ArgumentNullException - Thrown when elements is null.ArgumentOutOfRangeException - Thrown when an object of this type is constructed from an array with less than 4 elements.@Nonnull public static Quaternion getZero()
Quaternion coordinates with values of zero.@Nonnull public static Quaternion getUndefined()
Quaternion coordinates with values of Double.NaN.
Use IsUndefined (get) to test whether a Quaternion instance
is undefined since it will return true if any of the coordinate values
are Double.NaN.
@Nonnull public static Quaternion getIdentity()
Quaternion coordinates representing the identity vector.public final double getW()
public final double getX()
public final double getY()
public final double getZ()
@Nonnull public final Quaternion conjugate()
Quaternion.@Nonnull public final Quaternion multiply(double scalar)
Quaternion.scalar - The scalar.@Nonnull public final Quaternion multiply(@Nonnull Quaternion quaternion)
Quaternion, yielding a new Quaternion.quaternion - The quaternion.@Nonnull public final Quaternion multiply(@Nonnull ElementaryRotation rotation)
ElementaryRotation, yielding a new Quaternion.rotation - The elementary rotation.UnsupportedCaseException - Thrown if the Axis (get) property of rotation is
not AxisIndicator.FIRST, AxisIndicator.SECOND, or
AxisIndicator.THIRD.@Nonnull public static Quaternion multiply(@Nonnull Quaternion quaternion, double scalar)
Quaternion by a scalar, yielding a new Quaternion.quaternion - The quaternion.scalar - The scalar.@Nonnull public static Quaternion multiply(double scalar, @Nonnull Quaternion quaternion)
Quaternion, yielding a new Quaternion.scalar - The scalar.quaternion - The quaternion.@Nonnull public static Quaternion multiply(@Nonnull Quaternion quaternion, @Nonnull ElementaryRotation rotation)
quaternion - The quaternion.rotation - The elementary rotation.@Nonnull public static Quaternion multiply(@Nonnull Quaternion left, @Nonnull Quaternion right)
left - The first quaternion.right - The second quaternion.@Nonnull public static Quaternion negate(@Nonnull Quaternion coordinates)
Quaternion, yielding a new Quaternion.coordinates - The set of coordinates.Quaternion.public final int getLength()
public final double get(int index)
index of 0, 1, 2, and 3 corresponding to the coordinates
W (get), X (get), Y (get), and Z (get).index - The index to retrieve.index.ArgumentOutOfRangeException - Thrown when index is less than 0 or greater than or equal to Length (get).public boolean equals(Object obj)
equals in class Objectobj - The object to compare to this instance.true if obj is an instance of this type and represents the same value as this instance; otherwise false.Object.hashCode(),
HashMappublic final boolean equalsType(@Nonnull Quaternion other)
equalsType in interface IEquatable<Quaternion>other - The instance to compare to this instance.true if other represents the same value as this instance; otherwise false.public final boolean equalsEpsilon(@Nonnull Quaternion other, double epsilon)
equalsEpsilon in interface IEquatableEpsilon<Quaternion>other - The set of Quaternion coordinates to compare to this instance.epsilon - The limit at which the absolute differences between the coordinate values will not be considered equal.true if the absolute differences are less than or equal to epsilon; otherwise false.public int hashCode()
hashCode in class ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)public String toString()
public static boolean equals(@Nonnull Quaternion left, @Nonnull Quaternion right)
true if the two instances are exactly equal.left - The instance to compare to right.right - The instance to compare to left.true if left represents the same value as right; otherwise false.public static boolean notEquals(@Nonnull Quaternion left, @Nonnull Quaternion right)
true if the two instances are not exactly equal.left - The instance to compare to right.right - The instance to compare to left.true if left does not represent the same value as right; otherwise false.public final double getNorm()
public final double getNormSquared()
Norm (get) of this instance.public final boolean getHasZeroNorm()
Norm (get) of this instance is zero.public final boolean getIsUndefined()
Double.NaN.@Nonnull public static Quaternion toQuaternion(@Nonnull UnitQuaternion coordinates)
UnitQuaternion coordinates to a set of Quaternion coordinates.coordinates - The set of UnitQuaternion coordinates.Quaternion coordinates.@Nonnull public final UnitQuaternion normalize()
UnitQuaternion coordinates from this instance.
The normalization of the quaternion is accomplished in the usual way. It should be noted that this does not guarantee a result whose magnitude will be 1.0 in cases where an individual component underflows upon squaring.
UnitQuaternion coordinates.ArithmeticException - The magnitude of the provided coordinates must not be zero.NotFiniteNumberException - The magnitude of the provided coordinates must not be infinite.@Nonnull public final UnitQuaternion normalize(@Nonnull double[] magnitude)
UnitQuaternion coordinates from this instance
and returns the magnitude of the original instance in the provided parameter.
The normalization of the quaternion is accomplished in the usual way. It should be noted that this does not guarantee a result whose magnitude will be 1.0 in cases where an individual component underflows upon squaring.
magnitude - On input, an array with one element. On return, the array is populated with
the magnitude of the original set of Quaternion coordinates.UnitQuaternion coordinates.ArithmeticException - The magnitude of the provided coordinates must not be zero.NotFiniteNumberException - The magnitude of the provided coordinates must not be infinite.