public final class Quatd
extends java.lang.Object
implements java.lang.Cloneable
Methods with names ending in "Local" modify the current instance. They are used to avoid creating temporary objects.
Mathematically, quaternions are an extension of complex numbers. In mathematics texts, W often appears first, but here the conventional order is (X, Y, Z, W).
| Modifier and Type | Field and Description |
|---|---|
double |
w
The real (W) component.
|
double |
x
The first imaginary (X) component.
|
double |
y
The 2nd imaginary (Y) component.
|
double |
z
The 3rd imaginary (Z) component.
|
| Constructor and Description |
|---|
Quatd()
Instantiates an identity quaternion: all components zeroed except
w, which is set to 1. |
Quatd(double x,
double y,
double z,
double w)
Instantiates a quaternion with the specified components.
|
Quatd(Quatd quat)
Instantiates a copy of the argument.
|
Quatd(Quaternion quat)
Instantiates based on the specified (single-precision) Quaternion.
|
| Modifier and Type | Method and Description |
|---|---|
Quatd |
clone()
Creates a copy.
|
boolean |
equals(java.lang.Object o)
Tests for exact equality with the argument, distinguishing -0 from 0.
|
Quatd |
fromAngles(double xAngle,
double yAngle,
double zAngle)
Builds a Quaternion from the Euler rotation angles (x,y,z) aka
(pitch, yaw, roll).
|
int |
hashCode()
Returns a hash code.
|
Quatd |
inverse()
Returns the multiplicative inverse.
|
boolean |
isRotationIdentity()
Tests for an identity rotation.
|
boolean |
isZero()
Tests for a zero value.
|
double |
lengthSq()
Returns the squared length.
|
Quatd |
mult(Quatd q)
Takes the Hamilton product of the current instance times the argument to
yield a new Quatd.
|
Quatd |
mult(Quatd q,
Quatd result)
Takes the Hamilton product of the current instance times the first
argument and returns the product in the 2nd argument.
|
Vec3d |
mult(Vec3d v)
Rotates the argument vector to produce a new vector.
|
Vec3d |
mult(Vec3d v,
Vec3d result)
Rotates a specified vector and return the result in another vector.
|
Quatd |
multLocal(Quatd q)
Takes the Hamilton product of the current instance times the argument,
in place.
|
Quatd |
normalizeLocal()
Normalizes the current instance in place.
|
Quatd |
set(double x,
double y,
double z,
double w)
Sets all 4 components to the specified values.
|
Quatd |
set(Quatd q)
Copies all 4 components from the argument.
|
Quatd |
set(Quaternion quat)
Copies all 4 components of the specified (single-precision) Quaternion to
the current instance.
|
Quaternion |
toQuaternion()
Creates a (single-precision) Quaternion that approximates the current
instance.
|
Matrix3d |
toRotationMatrix()
Converts the quaternion to an equivalent rotation matrix.
|
java.lang.String |
toString()
Returns a string representation of the quaternion, which is unaffected.
|
public double x
public double y
public double z
public double w
public Quatd()
w, which is set to 1.public Quatd(double x,
double y,
double z,
double w)
x - the desired X componenty - the desired Y componentz - the desired Z componentw - the desired W componentpublic Quatd(Quatd quat)
quat - the quaternion to copy (not null, unaffected)public Quatd(Quaternion quat)
quat - the input Quaternion (not null, unaffected)public final Quatd clone()
clone in class java.lang.Objectpublic Quaternion toQuaternion()
public int hashCode()
hashCode in class java.lang.Objectpublic boolean equals(java.lang.Object o)
o is null, false is returned. Either way, the current instance is
unaffected.equals in class java.lang.Objecto - the object to compare (may be null, unaffected)this and o have identical values,
otherwise falsepublic boolean isRotationIdentity()
public boolean isZero()
public final Quatd set(double x, double y, double z, double w)
x - the desired X componenty - the desired Y componentz - the desired Z componentw - the desired W componentpublic final Quatd set(Quatd q)
q - the quaternion to copy (not null, unaffected)public final Quatd set(Quaternion quat)
quat - the input Quaternion (not null, unaffected)public final Quatd mult(Quatd q)
It IS safe for q and this to be the same object.
This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
q - the right factor (not null, unaffected)this * q (a new instance)public final Quatd mult(Quatd q, Quatd result)
result.
This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
It IS safe for any or all of q, result, and this
to be the same object.
q - the right factor (not null, unaffected unless it's
result)result - storage for the product, or null for a new Quatdthis * q (either result or a new Quatd)public final Quatd multLocal(Quatd q)
This method is used to combine rotations. Note that the Hamilton product is noncommutative, so generally q * p != p * q.
It IS safe for q and this to be the same object.
q - the right factor (not null, unaffected unless it's this)public Vec3d mult(Vec3d v)
v - the input vector (not null, unaffected)public Vec3d mult(Vec3d v, Vec3d result)
It IS safe for v and result to be the same object.
v - the vector to rotate (not null, unaffected unless it's
result)result - storage for the result (not null)resultpublic final double lengthSq()
public final Quatd normalizeLocal()
public Matrix3d toRotationMatrix()
Note: the result is created from a normalized version of the current instance.
public Quatd inverse()
null is returned. Either way, the current instance is unaffected.public Quatd fromAngles(double xAngle, double yAngle, double zAngle)
xAngle - the desired rotation about the +X axis (in radians)yAngle - the desired rotation about the +Y axis (in radians)zAngle - the desired rotation about the +Z axis (in radians)public java.lang.String toString()
Quatd[0.0, 0.0, 0.0, 1.0]
toString in class java.lang.Object